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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLINESIZE 255
main(int argc, char *argv[]) {
FILE *file_1 ;
FILE *file_2 ;
char file_1_stream[MAXLINESIZE] ;
char file_2_stream[MAXLINESIZE] ;
int lcr = 0 ; // for line check right
int lcw = 0 ; // for line check wrong
if (argc != 3) {
printf("usage: %s",argv[0]) ;
exit(1) ;
}
else {
file_1=fopen(argv[1],"r") ;
file_2=fopen(argv[2],"r") ;
if ( file_1 == NULL ) {
printf("unable to open file: %s",argv[1]) ;
exit(1) ;
}
else if ( file_2 == NULL ) {
printf("unable to open file: %s",argv[2]) ;
exit(1) ;
}
}
while ( ! ( fgets(file_1_stream,MAXLINESIZE,file_1) == NULL ) || ( fgets(file_2_stream,MAXLINESIZE,file_2) == NULL ) ) {
int lcc ; // for line check counter
printf("%s %s\n",file_1_stream,file_2_stream) ; // j'ai trouvé où est l'erreur seulement je ne sais d'où elle vient même avec fopen(argv[1|2]),"rb") j'ai ce problème...
size_t len ;
size_t check ;
check= (strlen(file_1_stream) == strlen(file_1_stream)) ? 1 : 0 ;
if ( ! check ) {
lcw++ ;
continue ;
}
else {
len = strlen(file_1_stream) ;
for ( lcc=0 ; file_1_stream[lcc] == file_2_stream[lcc] ; lcc++) {
;
}
if ( ! ( (int) len == lcc+1) ) {
lcw++ ;
continue ;
}
else {
lcr++ ;
continue ;
}
}
}
printf("diff %s %s\nlines equal: %i\nlines wrong: %i\n",argv[1],argv[2],lcr,lcw) ;
} |
Partager