(It's a homework assignment, so for the sake of education you probably shouldn't hand me a straight answer...or at least not all of it)
Anyway, supposed to open a text file and change user-defined words to *BLEEP*, then writing it to a new file. Supposed to get the list of words to 'censor' from command-line arguments and store them in a string array.
my printf statement in the while loop never prints anything, so i'm guessing there's an error with the evaluation but i'm not sure what it is...can anyone enlighten me?Code:#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXLEN 1000 int main(int argc, char *argv[]) { char buffer[MAXLEN]; char newbuffer[MAXLEN]; char *address; FILE *in = fopen("bleepIn.txt","r"); FILE *out = fopen("bleepOut.txt","w"); if(in == NULL) { fprintf(stderr,"ERROR"); exit(-1); } while(fgets (buffer,MAXLEN,in) != NULL) { if(strcmp(*argv,buffer) == 0) { address = strstr(*argv,buffer); printf("%s",address); //never runs strncpy(address,"*BLEEP*",10); strncpy(newbuffer,buffer,100); fputs(newbuffer,out); } else { strncpy(newbuffer,buffer,100); fputs(newbuffer,out); } } fclose(in); fclose(out); return 0; }



LinkBack URL
About LinkBacks
)


