Can you tell me if the declaration and definition below are correct ?
I had a "segmentation error" after puting some char in the array but I can't find my mistake.
Here is some lines of my code :
I had a "segmentation error" after puting some char in the array but I can't find my mistake.
Here is some lines of my code :
Code:
struct t_Zone
{
short zProfondeur, zLargeur;
char **Grille;
};
typedef struct t_Zone zone;
[\code]
...
[code]
char* initZone(int zProf, int zLarg, zone *t_Zone)
{
int i;
char msg[255];
t_Zone->zProfondeur = zProf;
t_Zone->zLargeur = zLarg;
t_Zone->Grille = calloc(zLarg,1);
if(t_Zone->Grille == NULL )
{
strcpy(msg,"NOT OK");
}
else strcpy(msg,"OK");
for( i=0 ; i<zProf && !strcmp(msg,"OK") ; i++)
{
t_Zone->Grille[i] = (char*)calloc(zProf+1,1);
if(t_Zone->Grille[i] == NULL)
{
strcpy(msg,"NOT OK");
}
else strcpy(msg,"OK");
}
return msg;
}
[\code]