我需要一些帮助,我无法理解为什么我的程序没有记录正确的数字。它将记录部分数字,但跳过其余部分。
示例(我希望如何):
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
但是当我运行代码时,我得到:
Player Name: Lev Yashin
Sign Up Time: 9 9
Sign In Time: 1 1
它看起来像传递零,我似乎不明白为什么这样做。我会不时地传递一些其他数据,它将产生所有数字。 有人对为什么它不包含一些数字有任何想法吗?
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;
}