【发布时间】:2014-05-09 09:54:37
【问题描述】:
这是从文件“F1.txt”中读取 10x10 矩阵的代码
#include <stdio.h>
int main( int argc, char ** argv ) {
FILE * fr;
fr = fopen("F1.txt","r");
int i, j;
int matrix[10][10] = {0.0};
for(i = 0; i < 10; i++)
{
for(j = 0; j < 10; j++)
{
fscanf(fr, "%d",&matrix[i][j]);
printf("%d\n", matrix[i][j]);
}
}
getchar();
return 0;
}
“F1.txt”看起来像这样:
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 4 34 56 43 32 124 52 212 3
32 343 34 544 43 32 7 52 456 98
它可以正常工作,但输出是:
12
343
34
544
43
32
124
52
212
3
12
343
34
544
43
32
124
52
212
..........
etc....
我必须检测行尾以使我的输入与 F1.txt 中的输入相同
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 4 34 56 43 32 124 52 212 3
32 343 34 544 43 32 7 52 456 98
.
【问题讨论】:
-
int matrix[10][10] = {0.0};你的意思是int matrix[10][10] = {0};,对吧? -
是的。它实际上在没有 = {0.0}; 的情况下运行
-
这个问题没有显示任何研究和努力。只需将
\n字符替换为` ` 将完成最大的工作。