這個程序是用C語言編寫結構返回錯誤-C
它應該得到兩d陣列(matrixAdd),並與scanMtx進行掃描(掃描功能是不是在這裏監守的代碼是不相關)
問題:EDMtx函數返回掃描矩陣1,1,1,,1,-8,1,,1,1,1 當它返回到主它是:0,0,0, 0,0,0,垃圾,垃圾,垃圾
似乎有一個地址錯誤
我做了什麼錯?
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
struct matrix
{
int* ptr;
int row;
int column;
};
matrix EDMtx();
void main(int argc, char* argv[])
{
int matrixAdd[5][5]={{1,1,1,3,4},{1,1,1,3,4},{1,1,1,3,4},{1,1,1,3,4},{1,1,1,3,4}};
matrix mtx;
matrix scanMtx;
mtx.ptr=&matrixAdd[0][0];
mtx.row=5;
mtx.column=5;
scanMtx= EDMtx();
// mtx= ScanM(mtx,1,1,scanMtx);- doesn't important to you.
getchar();
}
matrix EDMtx()
{
int matrx[3][3]={{1,1,1},{1,-8,1},{1,1,1}};
matrix Mtx;
Mtx.ptr=&matrx[0][0];
Mtx.row=3;
Mtx.column=3;
return Mtx;
}
只是一個問題:你是否得到編譯器警告? – mvds 2011-03-16 10:39:09
沒有編譯器警告或錯誤(使用微軟視覺) – 2011-03-16 10:41:31