this line of code
Code:
if ((i=getc(file_ptr)) != EOF)
will read one character and that one will be missing from user_score.
guess that should do what you want
Code:
/* INCLUDE STANDARD INPUT/OUTPUT FUNCTIONS */
#include <stdio.h>
#include <string.h>
/* OPEN FILE FOR READING INTO CONSOLE */
int main() {
FILE *file_ptr;
/* DELCARE VARIABLES TO STORE SCORE FILE DATA */
int user_score, i;
char user_handle[25];
/* CREATE A FILE POINTER TO OPEN RELEVANT FILE */
file_ptr = fopen("scores.txt", "r");
/* START LOOP TO READ THROUGH FILE & PROCESS FILE TO CONSOLE */
while ( 2 == fscanf(file_ptr, "%d %s", &user_score, user_handle) ) {
printf("\n %d %s", user_score, user_handle);
}
printf("\n");
fclose(file_ptr);
return 0;
}
This will loop as long as an int and string pair can be read (fsanf returning 2 ).
Kurt