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
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LINE 25
/* la column2 ne contient que des int */
int main()
{
char buf1[MAX_LINE];
char buf2[MAX_LINE];
FILE *infile1 = fopen("file1.txt", "r");
FILE *infile2 = fopen("file2.txt", "r");
FILE *outfile = fopen("matrice.txt", "w");
while (fgets(buf1, sizeof(buf1), infile1) != 0
&& fgets(buf2, sizeof(buf2), infile2) != 0) {
strchr(buf1, '\n')[0] = '\0';
char file1_column1[15] ;
int file1_column2;
sscanf(buf1, "%s %d", &file1_column1, &file1_column2);
char file2_column1[15] ;
int file2_column2;
sscanf(buf2, "%s %d", &file2_column1, &file2_column2);
fprintf(outfile, "%d %d\n",file1_column2,file2_column2);
}
fclose(outfile);
fclose(infile1);
fclose(infile2);
} |
Partager