You need to check feof() immediately after fscanf() or, conversely, check the return value from fscanf() . The latter is repeated because fscanf() does not read any new data in user.username and user.nickname due to reaching eof.
Possible fixes:
while(2 == fscanf(users_file, "%s %s", &user.username, &user.name)) { printf("%s | %s\n", user.username, user.nickname); }
or
enum { LINESIZE = 1024 }; char line[LINESIZE]; while (fgets(line, LINESIZE, users_file) && 2 == sscanf(line, "%s %s", &user.username, &user.name)) { printf("%s | %s\n", user.username, user.name); }
source share