Problème pour stocker dans un tableau
Bonjour, je souhaite faire un programme qui permet d'inverser une image PPM.
Pour cela je recopie l'entête et je stock la partie Ascii dans un tableau :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #include <stdio.h>
main(int arg , char **argv[]) {
FILE *f,*g;
printf("1er argument : %s\n" ,argv[1]);
printf("2eme argument : %s\n" ,argv[2]);
f = (FILE *) fopen (argv[1], "rb");
g = (FILE *) fopen (argv[2], "wb");
int hor, vert,i,x ;
int cpt = 0;
while (i != 10 ) { //1ere ligne de l'entete
i=fgetc(f);
fputc(i,g);
}
fscanf(f, "%d", &hor); //2eme ligne
fprintf(g,"%d",hor);
i=fgetc(f);
fputc(i,g);
fscanf(f, "%d", &vert);
fprintf(g,"%d",vert);
i=fgetc(f);
int mat[vert*hor];
while (!feof(f)) {
while (cpt < 2) { //3eme ligne
fputc(i,g);
if (i==10) {
cpt ++ ;
}
i=fgetc(f);
}
mat[x] = i;
i=fgetc(f);
x++;
}
fclose(f);
fclose(g);
} |
Le script compile parfaitement sous Code::Blocks avec Windows mais a l’exécution le programme plante .
Si quelqu'un a la réponse à mon problème.
Merci,