【发布时间】:2014-12-04 04:21:04
【问题描述】:
我在读取数组内容时遇到了一些问题。我不确定我是否正确存储它,因为每行的结果都是“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 是什么样的?它是一个数字列表,每行一个吗?
-
缓冲区溢出示例
标签: c arrays type-conversion fgets