有人可以帮我获取数据列和行的方式吗,一列的数字存储在一个数组中,第二列的存储在第二数组中,依此类推
这是文件的外观
我刚刚想出了如何一次获取所有数据的方法,但这并不能帮助我们
int i =0;
FILE* in_file = fopen("a2TestFile.txt", "r"); // read only
if(! in_file ) // equivalent to saying if ( in_file == NULL )
{
printf("oops, file can't be read\n");
exit(-1);
}
// attempt to read the next line and store
// the value in the "number" variable
while ( fscanf(in_file, "%d", & number[i] ) == 1 )
{
printf("We just read %d\n", number[i]);
i++;
}
for(int j=0;j<500;j++)
{
printf(number[j]);
}
答案 0 :(得分:0)
就像只使用以下命令吗?
fscanf(in_file, "%d %d %d %d", &col1[i], &col2[i], &col3[i], &col4[i]);