Originally Posted by
dmh2000
it helps if you post the contents of the input file and exactly what is printed for output.
Oops, I meant to do this.
input.txt
Code:
4
Bob 90
Eric 88
Sam 94
Lara 83
http://i.imgur.com/U1LD2.png
And I think I made those corrections @anduril462
Code:
#include <stdio.h>
typedef struct
{
char name[20];
short score;
}Student_Record;
int main()
{
FILE * ptr;
Student_Record test[20];
int count, k;
ptr = fopen("input.txt", "r");
if(ptr == NULL)
{
printf("Open operation failed.\n\n\n");
return 1;
}
fscanf(ptr, "%d", &count);
for(k = 0; k < count; k++)
{
fscanf(ptr, "%s%h", test[k].name, &test[k].score);
}
fclose(ptr);
printf("| Test Results |\n");
printf("|------------------|\n");
for(k = 0; k < count; k++)
{
printf("|%s |%d |\n", test[k].name, test[k].score);
}
printf("|------------------|\n");
getch();
return 0;
}
EDIT: Updated the input.txt and the image.