gpt4 book ai didi

C:从文件中读取某种格式的二维复数数组

转载 作者:行者123 更新时间:2023-11-30 17:49:55 25 4
gpt4 key购买 nike

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]。任何有关如何修改代码的建议将不胜感激!

最佳答案

试试这个

fscanf(fptB, "(%d, %d)%*c", &B[i][j].re, &B[i][j].im);

关于C:从文件中读取某种格式的二维复数数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17558442/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com