We help IT Professionals succeed at work.
Get Started

Scanf Blank Input

EvilGuru asked
Last Modified: 2012-06-21
Hi, in my program I need to get the users input, so I did all of the normal stuff, created a variable and then did scanf to fill it with the users input. However, it will not let the input be 'blank'. When I ask the user to type in their team name I want to give them the option of leaving it blank, rather than having to type in something (scanf will not take an input until a char other than crlf (eg the enter key) has been typed. How can I make it so that if the user does not want to type something in they can just press enter and have it go onto the next input.

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>

int main () {
    char input[80];
    printf("Please type in your team: ");
    scanf("%s", &input);
    if (input == "") strcpy(input, "default"); //set the team to default if left blank
    return 0;
As you can see it wont let them have a blank input, they have to try some kind of char, can anyone help me?
Watch Question
Top Expert 2005
This problem has been solved!
Unlock 1 Answer and 12 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE