I have a while loop reading names from a file and placing them in an array. When I print the contents of the array, it prints the last name that went through the loop, so I'm assuming that as the loop is progressing each time the names are being rewritten. I have attached my code, if you have any idea of what's wrong could you let me know please? My code is below.
if ((fp= fopen(filename, "r"))==NULL)
{
printf("Can't open %s.\n", filename);
return 1;
}
while ((fscanf(fp,"%s %s %c", last, first, &middle)) !=EOF)
{
k++;
printf("%s %s %c\n", last, first, middle);
sprintf(student_file, "%s %s %c", last, first, middle);
}
for( i=0; i<k; i++)
{
printf("%s\n", student_file);
}