Using scanf, with my initial prompt for input , the first character of the input string is truncated.
For example, if I enter George, only eorge is accepted from the keyboard. This only occurs on the first scanf. What am I doing wrong? See code below.
/* Prompt for initial input */
printf("\n Enter a student name (First Last) or (0) to Exit : ");
fflush(stdin); getchar();
scanf("%14[^\n]s", studentName);
while (studentName[0] != '0')
{
studentCount++;
fprintf(rpt, "\n %-18s %6.2f %18c", studentName, percentGrade, letterGrade);
printf("%s", studentName);
printf("\n Enter a student name (First Last) or (0) to Exit : ");
fflush(stdin); getchar();
scanf("%14[^\n]s", studentName);
}
Better:
Open in new window