seldon1 | Bon plus serieusement j'ai regardé la syntaxe de malloc mais je suis pas sur de mon coup car j'ai tjrs cette putain d'erreur de segmentation...
Code :
- #include <stdio.h>
- #include <stdlib.h>
- int Char2int(char s[])
- {
- int i,n;
-
- n=0;
- for(i=0;s[i]>='0'&&s[i]<='9';++i)
- n=10*n+(s[i]-'0');
- return n;
- }
- void initCarte(int taille,char *fname)
- {
- FILE * fp;
- int i,j;
- static char strProvi[10];
- int *carte[taille][taille];
-
- carte[0][0]=(int*)malloc(1000 * 1000 * sizeof(int));
-
- puts("ok2" );
- if ((fp = fopen(fname,"r" )) == NULL)
- {
- printf("Impossible d'ouvrir le fichier : %s\n",fname);
- exit(1);
- }
-
- puts("Lecture du fichier (+ de 20 secondes)." );
- fgets (strProvi, 10, fp);
- fgets (strProvi, 10, fp);
-
- puts("ok4" );
- for(i = 0; i < taille; i++)
- {
- for(j = 0; j < taille; j++)
- {
- fscanf(fp,"%d",*carte[i][j]);
- if (*carte[i][j]==255)
- {
- *carte[i][j]=0;
- }
- if (*carte[i][j]==2)
- {
- *carte[i][j]=1;
- }
- if (*carte[i][j]==251)
- {
- *carte[i][j]=2;
- }
- }
- }
- fclose(fp);
- for (int i = 0;i<taille;i++){
- fprintf(stderr,"\n" );
- for (int j =0;j<taille;j++)
- fprintf(stderr,"%d ", *carte[i][j]);
- }
-
- }
- int main(int argc, char *argv[])
- {
- int dimension;
- puts("ok1" );
- puts("entrez la taille de l'environnement :" );
- scanf("%d",&dimension);
- initCarte(dimension,"basic.txt" );
- puts("ok4" );
- }
|
|