Hi,
I'm still in the beginning stages of learning C so please bear with me.
I was wondering why my code would not read the user input for a string.
My code consisted of the following:
int main (void){
char userChar;
char userString[50];
printf("Enter character:\n");
scanf("%c", &userChar); //assigning input character//
printf("Enter string:\n");
scanf("%s", userString); //assigning input string//
printf("%c %s", userChar, userString);
return 0;
}
I wasn't getting an output for the userString unless I put a space in front of the %c for the scanf function, like so:
scanf(" %c", &userChar);
^
Only then would the userString print.
Would anyone be able to tell me what difference that little space makes???
I'm still in the beginning stages of learning C so please bear with me.
I was wondering why my code would not read the user input for a string.
My code consisted of the following:
int main (void){
char userChar;
char userString[50];
printf("Enter character:\n");
scanf("%c", &userChar); //assigning input character//
printf("Enter string:\n");
scanf("%s", userString); //assigning input string//
printf("%c %s", userChar, userString);
return 0;
}
I wasn't getting an output for the userString unless I put a space in front of the %c for the scanf function, like so:
scanf(" %c", &userChar);
^
Only then would the userString print.
Would anyone be able to tell me what difference that little space makes???