我在阅读我的数组内容时遇到了一些问题。我不确定是否正确存储它,因为我的结果是每行都是'1304056712'。正确地按行存储文件内容并稍后打印数组内容
#include <stdio.h>
#include <stdlib.h>
#define INPUT "Input1.dat"
int main(int argc, char **argv) {
int data_index, char_index;
int file_data[1000];
FILE *file;
int line[5];
file = fopen(INPUT, "r");
if(file) {
data_index = 0;
while(fgets(line, sizeof line, file) != NULL) {
//printf("%s", line); ////// the line seems to be ok here
file_data[data_index++] = line;
}
fclose(file);
}
int j;
for(j = 0; j < data_index; j++) {
printf("%i\n", file_data[j]); // when i display data here, i get '1304056712'
}
return 0;
}
Input1.dat文件是什么样的?它是一个数字列表,每行一个? – 2014-12-04 04:35:58
缓冲区溢出示例 – 2014-12-04 04:39:52