/* license : GPL author ; Nicola Piazzolla */ #include #include #include #define MAX_STRING 1000 #define FLAG_READ "r" #define FLAG_WRITE "a+" #define pathname "NEW_FILE_MODIFIED" void __writefile__ ( char *sentence , char *file ) { FILE *fd; fd=fopen(pathname,FLAG_WRITE); fprintf(fd,"%s",sentence); fclose(fd); } int scan(char *word, char *scanword, char *file) { char copy[MAX_STRING]; int j, i = 0; int o =0; j = i; bzero(copy,MAX_STRING); while (scanword[j] != '\0') { while (word[i] != '\0' ) { if (scanword[j] != word[i]) { copy[o]=word[i]; o++; } i++; } j++; i=0; o=0; strcpy(word,copy); bzero(copy,MAX_STRING); } __writefile__(word,file); return 0 ; } int __openfile__(char *file, char *word ) { FILE *fd; char sentence[MAX_STRING]; int i; if ((fd = fopen(file, FLAG_READ)) == NULL) { printf("The file doesnt exist\n"); exit(-1); } while (!feof(fd)) { bzero(sentence, MAX_STRING); fgets(sentence, MAX_STRING, fd); if ( (i=scan(sentence, word, file) ) != 0) { fprintf(stderr,"Scan has failed\n"); } } fclose(fd); return 1; } int main(int argc, char **argv) { FILE *fd ; int check; if ( (fd=fopen(pathname,FLAG_READ)) != NULL ) { remove(pathname); } if (argc < 3) { fprintf(stderr, " >>> Type %s [file] [characters] <<< \n",argv[0]); } else { if ( (check=__openfile__(argv[1], argv[2])) != 1 ) { fprintf(stderr,"I cannot open the file ...\n"); } } }