I'm trying to read user input and store it as a string including the whitespace. I did a search for a solution and was pointed to fgets() or scanf(%[^\n], str). But both these solutions give me an error.
This is what I have:
scanf("%d", &input);
if (input == 1){
int pr;
char na[MAX_CHARACTERS+1];
printf("\nEnter the name: ");
scanf("%[^\t\n]", &na);
while (strlen(na)>MAX_CHARACTERS){
printf("\nName is too long, enter new name: ");
scanf("%[^\t\n]", &na);
}// end na check
printf("\nEnter priority: ");
scanf("%d", &pr);
while (pr>MAX_PRIORITY || pr <MIN_PRIORITY){
printf("\nBad priority, enter new priority (0-100): ");
scanf("%d", &pr);
}//end pr check
It works fine if I use %s in all instances of %[\t\n] but when I use %[\t\n] or replace scanf() with fgets(na, 30, stdin), it skips the first scanf for name and goes straight to "Enter priority: ".
Then when it prints, I get a blank name with whatever priority I entered.