2

I need some help I cannot understand why my program doesn't record the right numbers. It will record parts of the number but skip the rest.

Example (How I want it):

Player Name: Lev Yashin
Sign Up Time: 9 09
Sign In Time: 1 01
Player Name: Andrei Arshavin
Sign Up Time: 6 09
Sign In Time: 12 15
Player Name: Igor Akinfeev
Sign Up Time: 7 36
Sign In Time: 5 29
Player Name: Igor Netto
Sign Up Time: 4 28
Sign In Time: 7 29

But when I run my code, I get:

Player Name: Lev Yashin
Sign Up Time: 9 9
Sign In Time: 1 1

Its looking like it passes zeros, and I can't seem to understand why it does it. Once and awhile I will pass in some other data and it will produce all the numbers. Anyone have any ideas on why it doesn't include some numbers?

int modifyStr(FILE *soccerWebsiteData, char firstAndLast[], char *pSignUpHours, char *pSignUpMinutes, char *pSignInHours, char *pSignInMinutes) {
char *position = NULL;
char oneLineOfFile[MAX_LENGTH];
char signUpHours = 0, signUpMinutes = 0, signInHours = 0, signInMinutes = 0;

while (!feof(soccerWebsiteData)) {
    fgets(oneLineOfFile, MAX_LENGTH, soccerWebsiteData);
    position = strchr(oneLineOfFile, ',');

    strncpy(firstAndLast, oneLineOfFile, (position - oneLineOfFile));
    firstAndLast[(position - oneLineOfFile)] = '\0';

    signUpHours = atoi(position + 1);
    *pSignUpHours = signUpHours;

    position = strchr(position, ':');

    signUpMinutes = atoi(position + 1);
    *pSignUpMinutes = signUpMinutes;

    position = strchr(position + 1, ',');

    signInHours = atoi(position + 1);
    *pSignInHours = signInHours;

    position = strchr(position, ':');

    signInMinutes = atoi(position + 1);
    *pSignInMinutes = signInMinutes;

    printf("Player Name: %s \n", firstAndLast);
    printf("Sign Up Time: %d %d \n", signUpHours, signUpMinutes);
    printf("Sign In Time: %d %d \n", signInHours, signInMinutes);
}
return 0;

}

Sergei
  • 21
  • 1

0 Answers0