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 61 62 63 64 65 66 67
| #include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <assert.h>
int cherche_fichier(char *s, char *chemin){
char string[1000];
int nb = 1;
int q = 0;
FILE *original = NULL;
FILE *copy = NULL;
original = fopen (chemin, "r");
copy = fopen ("copy.txt", "w+");
if (original != NULL){
while(fscanf(original, "%1000s %d", string,&nb) > 0) {
printf("s = %s et string = %s\n",s, string);
if (strcmp(s,string) == 0){
fprintf(copy, "%s %d ",string,nb+1);
q = 1;
printf("lol");
break;}
fprintf(copy, "%s %d ",string,nb);}}
fclose(original);
fclose(copy);
return q;
}
void lire_mot(char * chemin){
char s[1000];
int i;
int q;
FILE *out = NULL;
FILE *fichier = NULL;
fichier = fopen (chemin, "w+"); //argv[1]
if (fichier != NULL){
fputs("Jaime les litchis, mais c'est mo8ins \nbon que les \npeches",fichier); //écrit dans le fichier pour le test
rewind(fichier); // remet le curseur au début
while(fscanf(fichier,"%1000s ", s) > 0) {
i=0;
while( s[i] ) { //b--met en minuscule le mot
s[i]= tolower(s[i]);
if ((int)s[i] >= 48 && (int)s[i] <= 57){
printf("nombre");}
i++;}printf("\n"); //f--
printf("s : %s\n",s);
q = cherche_fichier(s, "out.txt");
if (q == 0){
out = fopen ("out.txt", "a+");
fprintf(out, "%s 1 ",s);
fclose(out);}}}
fclose(fichier);
}
int main(int argc, char *argv[]) {
lire_mot("test.txt");
return EXIT_SUCCESS;
} |
Partager