0

Well I got this issue and I don't get why? If someone could explain I'm just trying to learn C lmao

I don't even have a clue of where I'm supposed to let it implicitly declare this function as something else than a struct Map*, if someone can explain I would be gratefull.

The error I got in my terminal

#include <stdio.h>
#include <stdlib.h>


struct Map{
    unsigned int DimX;
    unsigned int DimY;
    char** Map;


};


void main(){
    printf("Hello world, at least it compiled\n");
    unsigned int DimX = 10;
    unsigned int DimY = 10;
    struct Map* M = InitMap(DimX, DimY);
    PrintMap(M);





}


//Initialise the map with 0 everywhere
struct Map* InitMap(unsigned int DimX,unsigned int DimY){
    struct Map* M;
    M = malloc(sizeof(struct Map));
    M->DimX = DimX;
    M->DimY = DimY;
    M->Map = malloc(sizeof(char*)*DimX);
    for(int i = 0; i < DimX; i++){
        M->Map[i] = malloc(sizeof(char)*DimY);
        for(int j = 0; j < DimY; j++){
            M->Map[i][j] = 0;
        }
    }
    return M;


}

Well I did try to cast it explicitely as a struct Map* but it didn't worked...

I just want it to intialize the matrix of a DimX * DimY with 0 for the moment...

  • 2
    Function must be declared before their usage. – Vlad from Moscow Jun 10 '23 at 21:56
  • General rule: You should start with the first warnings you got. Every other warning or error could just be caused by that same line. In your case also the first warning shows you the error: Implicit declaration of your function. Implicit declarations follow some rules that you did not obey. This is common source of errors which probably is why they are not allowed anymore. – Gerhardh Jun 11 '23 at 10:34

0 Answers0