-1
#include <stdio.h>
FILE *fl;
char content[BUFSIZ];
int main() {
int i;
fl = fopen ("data.txt", "rt");
content = fgetc(fl);
for (i=0;i <= sizeof(content); i++){
printf("%c",content[i]);
}
fclose(fl);
}
我试图打开文件并将文本文件的内容放入content []数组中。但是当我尝试编译时,我得到以下错误。如何打开文件并将其放入数组中,C
y:~/homework1: gcc -o hw1_2 hw1_2.c
hw1_2.c: In function 'main':
hw1_2.c:11:11: error: incompatible types when assigning to type 'char[1024]' from type 'int'
谢谢。 fread(content,1,sizeof(content),fl);'完美地工作。 – 2012-01-31 18:29:30