Normally, you use fgets to read a whole line, then use sscanf (or whatever you want) to extract the information from the line.
Code:
#include <stdio.h>
int ReadFile ( FILE *fin, char (*CharArrayPtr)[20], int *IntArrayPtr ) {
char buff[BUFSIZ];
int i = 0;
rewind ( fin );
// read each line from the file
while ( fgets ( buff, BUFSIZ, fin ) != NULL ) {
// if it contains the data we expect
if ( sscanf( buff, "%s %d", CharArrayPtr[i], &IntArrayPtr[i]) == 2 ) {
// then increment the count
i++;
} else {
// some error message perhaps
}
}
return i;
}
int main ( ) {
char names[100][20];
int scores[100];
int n = ReadFile( stdin, names, scores );
int i;
printf( "%d records\n", n );
for ( i = 0 ; i < n ; i++ ) {
printf( "%2d: %s %d\n", i, names[i], scores[i] );
}
return 0;
}