File I/O editing problems

This is a discussion on File I/O editing problems within the C Programming forums, part of the General Programming Boards category; (It's a homework assignment, so for the sake of education you probably shouldn't hand me a straight answer...or at least ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    7

    File I/O editing problems

    (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.

    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;
    }
    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?

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,501
    Read up on argv - Try and find some examples on how people are using it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ XML file editing
    By nick753 in forum C++ Programming
    Replies: 1
    Last Post: 12-26-2011, 11:40 AM
  2. Editing an include.h file
    By Char*Pntr in forum C Programming
    Replies: 5
    Last Post: 08-16-2010, 12:31 PM
  3. editing large file
    By arcamot in forum Windows Programming
    Replies: 7
    Last Post: 09-07-2007, 07:48 PM
  4. Editing a text file
    By chimpanzee in forum C++ Programming
    Replies: 3
    Last Post: 01-22-2006, 04:47 AM
  5. editing file
    By hmunhung in forum C++ Programming
    Replies: 2
    Last Post: 08-23-2002, 04:02 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21