2015-04-02 48 views
0

你們可以幫助我理解函數m嗎?我們的想法是對printf「標籤」,但我不明白什麼是錯的C下標值既不是數組也不是指針也不是矢量

#include <stdio.h> 
#define MAXL 50 
#define MAXC 50 
unsigned int linhas; 
unsigned int colunas; 
int segC [MAXL]; 
int segL [MAXC]; 
char tab[MAXL][MAXC]; 

void c(){ 
    int l,c,temp; 
    scanf("%d %d",&linhas,&colunas); 
    for (l=0;l<linhas;l++){ 
     scanf("%d[^'']",&temp); 
     segC[l]=temp; 
    } 
    for (c=0;c<colunas;c++){ 
     scanf("%d[^'']",&temp); 
     segC[c]=temp; 
    } 

    for(l=0;l<=linhas;l++){ 
     for(c=0;c<colunas;c++){ 
      scanf("%c",&tab[l][c]); 
     } 
    } 


} 

char m (linhas,colunas,segC,segL,tab){ 
    int l,c; 
    int tempi; 
    char tempc; 
    for(l=0;l<=linhas;l++){ 
     for(c=0;c<colunas;c++){ 
      printf("%c",tab[l][c]); 
     } 
     tempi=segL[l]; 
     printf("%d\n",tempi); 
    } 
    for(c=0;c<colunas;c++){ 
     tempi=segC[c]; 
     printf("%d",tempi); 
    } 
    printf("\n"); 
} 

char h (int line){  
} 
int main(){ 
    c(); 
//m(linhas,colunas,segC,segL,tab); 
} 
+1

哪條線路給您造成麻煩;請給出錯誤信息並解決問題 – 2015-04-02 21:00:25

+0

是的,任何像樣的編譯器都會給你一些警告,首先消除這些警告。 – 2015-04-02 21:03:30

+0

順便說一句''%d [^'']「' - >'」%d「' – BLUEPIXY 2015-04-02 21:29:02

回答

0

你缺少變量類型:

char m (linhas,colunas,segC,segL,tab) 
0

改寫這樣的功能:

char m() { 
    /* ... */ 
} 

您不需要將全局變量作爲參數提供給函數;實際上,局部函數參數會影響全局變量。

最後,避免省略參數和變量類型;至少在C99中至少被棄用或者甚至是非法的(省略類型默認爲int,這導致了這裏的問題。)

更好的是,在main()中聲明它們爲局部變量,並通過僞參考既m()c():打電話時

char m(unsigned int linhas, unsigned int colunas, int **segC, int **segL, char ***tab) { 
    /* ... */ 
} 

傳遞segC,SEGL的地址和標籤。

相關問題