简体   繁体   English

C下标值既不是数组也不是指针也不是向量

[英]C subscripted value is neither array nor pointer nor vector

Can you guys help me on function m? 你们可以在功能m上帮助我吗? The idea is to printf the "tab", but i don't understand what is wrong 这个想法是用printf的“标签”,但我不明白这是怎么回事

#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.) 从C99开始,至少是不推荐使用甚至是非法的(忽略的类型默认为int,这在这里引起了问题。)

Better yet, declare them as local variables in main() and pass them by pseudo-reference to both m() and c() : 更好的是,在main()中将它们声明为局部变量,并通过伪引用将它们传递给m()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. 调用时传递segC,segL和tab的地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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