Code:
for (l= 0; l < 3; l++);
{
printf ("%.2f, ", input[l].grade[l]);
}
This loop comes with a costly typo - notice the semicolon on the end of the closing parens. This explains the problem, because l is actually 3 when you get to the printf statement, causing out of bounds access. You are also using scanf() incorrectly, at least according to my manual. Specification for precision is printf only. Since you want to read stuff like "1", "2", "3" anyway, it doesn't make sense to try.
I made some functions when I tested your I/O, might want to see them:
Code:
void GetString(char *string, size_t maxLength)
{
if (fgets(string, maxLength, stdin) != NULL) {
char *eol = strchr(string, '\n');
if (eol != NULL) {
*eol = '\0';
}
}
}
float GetGrade(void)
{
float grade=0.0f;
int check = scanf("%f", &grade);
while (check != 1) {
int c;
fprintf(stderr, "GetGrade error: reading error\n");
while ((c = getchar()) != '\n' && c != EOF)
/*continue*/ ;
printf("Try again:\n");
check = scanf("%f", &grade);
}
return grade;
}
Optional improvement if you want it.