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 38 39 40 41 42 43 44
| #include <stdio.h>
#include <stdlib.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 ;
int cpt = 0;
while (i != 10 ) {
i=fgetc(f);
fputc(i,g);
}
fscanf(f, "%d", &hor); //1ere ligne de l'entete
fprintf(g,"%d",hor);
i=fgetc(f);
fputc(i,g);
fscanf(f, "%d", &vert);//2eme ligne
fprintf(g,"%d",vert);
i=fgetc(f);
fputc(i,g);
fscanf(f, "%d", &i); //3eme ligne
fprintf(g,"%d",i);
i=fgetc(f); //le saut a la ligne
fputc(i,g);
int *mat = NULL;
mat = malloc(sizeof(int) * vert*hor);
int x =0;
int y = 0;
while ((i = getc(f))!=EOF && x < vert*hor) {
mat[x] = i;
x++;
}
for (x = 0 ; x < vert*hor ; x++) {
fputc(mat[x],g);
}
if(feof(f)) {
fclose(f);
fclose(g);
}
} |
Partager