我已编写此代码,以尝试读取.txt文件。尝试运行它时,我得到以下结果...
foreach ($things as $thing ) {
if ($thing == null) {
//do stuff and skip loop iteration
continue;
}
//Things written from this point on act as "else"
}
我不确定如何解决此问题。非常感谢
答案 0 :(得分:0)
这里
Students[line] = num;
Line
不会改变,即总是0
,因此可以增加它或使用循环变量。对于例如
for(int i = 0; i < 100 && ( fscanf(pToFile, "%d", &num) == 1); ++i) {
Students[i] = num
printf("%d ", Students[i]);
}
并始终检查fopen()
的返回值是否知道对fopen()
的调用是否成功。对于例如
File *pToFile = fopen("Marks.txt","r");
if(pToFile == NULL) {
/* @TODO error handling */
return 0;
}
答案 1 :(得分:0)