2016-03-06 69 views
-1

我知道這個問題無處不在,但我找不到解決方案,在這一點上我非常沮喪。 我想要做的是創建和使用靜態庫。得到了最後一點,我需要建立解決方案,但我不斷收到此錯誤。我知道代碼有一些東西,也許更多,可能是完整的,但是經過幾個小時和幾個小時試圖使它工作,我真的不會看到它。你知道,「你不能看到森林,因爲樹」W/e。這裏有一些屏幕。錯誤C4700:未初始化的本地變量「」使用

enter image description here

enter image description here

#include <iostream> 
#include <conio.h> 
#include "matrice.h" 

void din_alocation(int n, int m){ 
    float **mat; 
    mat = (float**)calloc(n, sizeof(float*)); 
    for (int i = 0; i < n; i++) 
     mat[i] = (float*)calloc(m, sizeof(float)); 
} 
void read(float **mat, int n, int m){ 
    for (int i = 0; i < n; i++) 
    for (int j = 0; j < m; j++) { 
     printf("mat[%d][%d]= ", i, j); scanf_s("%f", &mat[i][j]); 
    } 
} 
void write(float **mat, int n, int m){ 
    for (int i = 0; i < n; i++){ 
     printf("\n"); 
     for (int j = 0; j < m; j++) 
      printf("%.2f ", mat[i][j]); 
    } 
} 

void din_realocation(float **mat, int n){ 
    for (int i = 0; i < n; i++) 
     free(mat[i]); 
    free(mat); 
} 

回答

0

錯誤應該很清楚。您不需要在main函數中的任何位置初始化變量mat

一種解決方案是爲din_alocation函數返回它分配的數據,然後做

mat = din_alocation(x, y); 
+0

不要,在過去,但我不斷收到的2個錯誤: LNK1120:1無法解析的外部(文件test.exe) 錯誤錯誤LNK2019:函數_main中引用的無法解析的外部符號「float * * __cdecl din_alocation(int&,int&)」(?din_alocation @@ YAPAPAMAAH0 @ Z) (file is test.obj) –

+0

是的,對不起,保持點擊進入而不是Shift + Enter。 –

+0

@ sNow11你已經改變了函數的定義(實現)來實際返回一個'float **'? –