This is my first example program writing to files. Right now, I know nothing on the matter. I do know that scanf can be finicky about taking input, but I have no idea why at this point. The problem occurs in the while loop
Code:
#include <stdio.h>
int main()
{
int account;
char name[ 30 ];
double balance;
FILE *cfPtr;
if ( ( cfPtr = fopen( "client.dat", "w" ) ) == NULL )
printf( "File could not be opened\n" );
else {
printf( "Enter the account, name, and balance.\n" );
printf( "Enter EOF to end input.\n" );
printf( "? " );
scanf( "%d%s%lf", &account, name, &balance );
/* ------------------------------THIS IS WHERE IT LOOPS INFINITELY--------------*/
while ( !feof( stdin ) ) {
fprintf( cfPtr, "%d %s %.2f\n",
account, name, balance );
printf( "? " );
scanf( "%d%s%lf", &account, name, &balance );
}
fclose( cfPtr );
}
return 0;
}