[問題] 用fscanf讀整數發生一些問題
教授出了一個作業是要用一個 n*n+1 的二維陣列讀入他給的data.dat檔案中的數字(這
檔案很大,一般文書處理軟體開不起來),然後經過高斯消去法求解之後代回去算誤差,
可是我用fscanf讀入時卻變成全部都讀入1,而其他同學則是其他數字,想請問一下是不
是哪邊寫錯了,下面是我寫的程式碼的前面部分
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int size, row, column, i, j;
double **matrixA, **matrixB , *matrixC, errorT = 0.0, error = 0.0;
FILE *fp, *fi;
fp = fopen("data.dat","r");
fi = fopen("resultDouble.txt","w");
clock_t start, end;
for(size = 100;size <= 9900;size += 100) //目前為size階陣列
{
start = clock(); //標記開始時間
//動態配置陣列大小
matrixA = (double **) malloc(size * sizeof(double *));
for(i=0;i <= size-1;i++)
matrixA[i]=(double *)malloc((size+1) * sizeof(double));
matrixB = (double **) malloc(size * sizeof(double *));
for(i=0;i <= size-1;i++)
matrixB[i]=(double *)malloc((size+1) * sizeof(double));
matrixC = (double *) malloc((size+1) * sizeof(double));
//進行讀取,matrixA進行運算,matrixB則不動,作為對照
for(row = 0;row <= size-1;row++) //從列1~列尾
for(column = 0;column <= size;column++) //從行1~行尾
matrixA[row][column]=fscanf(fp,"%lf",&matrixA[row][column]);
for(row = 0;row <= size-1;row++)
for(column = 0;column <= size;column++)
matrixB[row][column]=fscanf(fp,"%lf",&matrixB[row][column]);
感謝各位
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.120.222.33
推
10/22 11:55, , 1F
10/22 11:55, 1F
→
10/22 11:55, , 2F
10/22 11:55, 2F
→
10/22 11:56, , 3F
10/22 11:56, 3F
→
10/22 11:56, , 4F
10/22 11:56, 4F
推
10/22 12:18, , 5F
10/22 12:18, 5F
推
10/22 12:22, , 6F
10/22 12:22, 6F
→
10/22 12:43, , 7F
10/22 12:43, 7F
推
10/22 19:09, , 8F
10/22 19:09, 8F
→
10/22 19:09, , 9F
10/22 19:09, 9F