So here is my problem. I am trying to make a program that can calculate some statistics by reading a random access file and hereby process the information in order to calculate the, numberofredcards and total goals for a soccer season. The file is already made but i can't figure out how to process the information in the file. the program will print and read the file but how will i be able to use that data in the file? I know the program already is reading and recording from the file. Hope somebody could help.
struct clientData {
int numberofgoals;
char teamname[ 30 ];
double numberofredcards;
};
int main( void ) {
FILE *cfPtr;
struct clientData client = { 0, "", 0.0 };
if ( ( cfPtr = fopen( "credit.dat", "rb" ) ) == NULL ) {
printf( "File could not be opened.\n" );
}
else {
printf( "%-6s%-16s%-11s\n", "Number of goals", "Teamname", "Number of red cards" );
while ( !feof( cfPtr ) ) {
fread( &client, sizeof( struct clientData ), 1, cfPtr );
if( client.numberofgoals != 0 ) {
printf( "%-6d%-16s%-11f\n",
client.numberofgoals, client.teamname, client.numberofredcards );
}
}
fclose( cfPtr );
}
return 0;
}
thanks!

New Topic/Question
Reply



MultiQuote





|