-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