0
votes

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);
}
2
Which lines are causing you trouble; please give error messages and solve attempts - user4413591
Yes, any decent compiler should throw you some warnings, eliminate these first. - Jens Gustedt
BTW "%d[^'']" --> "%d" - BLUEPIXY

2 Answers

0
votes

You're missing variable types:

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

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.