【发布时间】:2015-02-19 14:31:46
【问题描述】:
#include "stdio.h"
main( ) {
FILE *fp1;
char oneword[100];
char *c;
fp1 = fopen("TENLINES.TXT","r");
do {
c = fgets(oneword, 100 ,fp1); /* get one line from the file */
if (c != NULL)
printf("%s", oneword); /* display it on the monitor */
} while (c != NULL); /* repeat until NULL */
fclose(fp1);
}
我不明白为什么这段代码需要一个 char *c。 char *c 在这里做什么。我试图将所有的“c”更改为“oneword”,但它总是会出错。你能解释一下吗? 谢谢。
【问题讨论】:
-
如果文件不存在或由于某种原因您无法打开它,该程序将调用未定义的行为。
-
推荐
#include<stdio.h>。这个和你原来的有区别。 -
请修正你的缩进。
标签: c