【发布时间】:2013-07-09 21:19:44
【问题描述】:
一个 2x2 复数矩阵
1+2i 3+4i
5+6i 7+8i
保存在mat.txt中,格式为
(1, 2) (3, 4)
(5, 6) (7, 8)
如何将其读取到 C 中的矩阵中,以便
B[0][0].re = 1, B[0][0].im = 2
B[0][1].re = 3, B[0][1].im = 4
B[1][0].re = 5, B[1][0].im = 6
B[1][1].re = 7, B[1][1].im = 8
?
我有
fptB = fopen("mat.txt","r");
for(i=0; i <2; i++){
for (j=0; j<2; j++){
fscanf(fptB, "(%d, %d)", &B[i][j].re, &B[i][j].im);
}
}
fclose(fptB);
但它只读取 B[0][0]。任何有关如何修改代码的建议将不胜感激!
【问题讨论】:
标签: c arrays matrix scanf complex-numbers