新手菜鸟求问fscanf读取文件数据存入数组问题
生成数组s[3][3]存放到z.txt里,然后从中读取出来存放到t[3][3],但不知道是不是指针哪里出了问题,读取结果总是溢出了#pragma warning(disable:4996)
#include<stdio.h>
#include<math.h>
int main() {
FILE* z;
z = fopen("zg.txt", "wt+" );
float s[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
s[i][j] = (float)i + j;
fprintf(z, "%f ", s[i][j]);
}
fprintf(z, "\n");
}
float t[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
fscanf(z, "%f", &t[i][j]);
}
fscanf(z, "\n");
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
printf("%f ", t[i][j]);
}
printf("\n");
}
system("pause");
return 0;
}