更新时间:1970-01-01 07:55:42
某些问题
使用 fgets()
缓冲区而不检查结果.尝试使用 szInputBuffer
之前,请检查 fgets()
的结果.不需要进一步的 feof()
检查. @kaylum
Using the fgets()
buffer without checking the result. Check the result of fgets()
before attempting to use szInputBuffer
. Further feof()
check not needed. @kaylum
// while(!feof(pFileTeam)) {
// fgets(szInputBuffer, 100, pFileTeam);
// sscanf(szInputBuffer, ....
while(fgets(szInputBuffer, sizeof szInputBuffer, pFileTeam) != NULL) {
sscanf(szInputBuffer, ....
使用幻数.考虑一下256. szInputBuffer []
没那么大.
char szInputBuffer[100];
...
// fgets(szInputBuffer, 256, pFileTeam);
if (fgets(szInputBuffer, sizeof szInputBuffer, pFileTeam) == NULL) break;
无用格式.%[^,]%[^,] ..."
尝试读取直到','
和 leaves 在文件流中','
而不读取它. @ user3121023 .健壮的代码限制了字符串输入并检查 sscanf()
结果.
Useless format. "%[^,]%[^,]..."
attempts to read text up to a ','
and the leaves that ','
in the file stream without reading it. @user3121023. Robust code limits string input and checks sscanf()
results.
// sscanf(szInputBuffer, "%[^,]%[^,]%[^,]%[^\n]", teams.szTeamName, ...
// Assuming szTeamName[10]
if (4 != sscanf(szInputBuffer, "%9[^,],%9[^,],%9[^,],%9[^\n]", teams.szTeamName, ...) {
break;
}
也许其他问题.
Maybe others issues.