I need help...I can create the file...write to the file...but when I end the file...it gives me endless cursors until I close the window...when I go to the read program it it gives me endless replays of the last item listed in the file.......
Code:
#include <stdio.h>
int main()
{
int StudentSSN; /* Social Security Number */
char StudentName [ 30 ]; /* Name up to 30 characters */
double StudentAverage; /* Average Grade */
FILE *cfPtr; /* cfPtr = clients.dat file pointer */
/* fopen opens file. Exit program if unable to create file */
if ( ( cfPtr = fopen( "student.dat", "w" ) ) == NULL ) {
printf( "File could not be opened\n" );
} /* end if */
else {
printf( "Enter the StudentSSN,StudentName, and STudentAverage.\n" );
printf( "Enter EOF to end input.\n" );
printf( "? " );
scanf( "%d%s%lf", &StudentSSN, StudentName, &StudentAverage );
/* write Student SSN, Student Name and Student Average into file with fprintf */
while ( !feof( stdin ) ) {
fprintf( cfPtr, "%d %s %.2f\n", StudentSSN, StudentName, StudentAverage );
printf( "? " );
scanf( "%d%s%lf", &StudentSSN, StudentName, &StudentAverage );
} /* end while */
fclose( cfPtr ); /* fclose closes file */
} /* end else */
return 0; /* indicates successful termination */
} /* end main */