简体   繁体   中英

C subscripted value is neither array nor pointer nor vector

Can you guys help me on function m? The idea is to printf the "tab", but i don't understand what is wrong

#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);
}

您缺少变量类型:

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

Rewrite the function like this:

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

You do not need to provide global variables as arguments to a function; in fact, the local function parameters shadow the global variables.

Finally, avoid omitting parameter and variable types; that is at the very least deprecated or even illegal as of C99 (omitted types default to int which is causing the problem here.)

Better yet, declare them as local variables in main() and pass them by pseudo-reference to both m() and c() :

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

Pass the address of segC, segL, and tab when calling.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM