我想通过引用传递流,这是一个指针。所以我将它作为指针传递给指针。有人可以验证我的代码吗?通过引用传递流
int main(int argc, char** argv)
{
FILE *stream;
printf("LINES: %d\n",scan(stream));
}
int scan(FILE *(*stream))
{
stream = fopen("names.txt", "r");
int ch = 0, lines=0;
while (!feof(*stream))
{
ch = fgetc(*stream);
if (ch == '\n')
{
lines++;
}
}
fclose(*stream);
return lines;
}
未收到输出。
[while-feof-file-is-always-wrong](http://stackoverflow.com/a/5432517/3386109) – user3386109 2015-03-02 07:10:32
_可以让别人验证我的代码吗?_编译器会验证你的代码。 – 2015-03-02 07:13:05
@ user3386109这没有错。我有测试,它的工作原理。 – user3337714 2015-03-03 02:39:43