Thread: Change character in file?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    1ST » R. vd Kooij
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    154

    Change character in file?

    Hi, been searching but can't find anything... no idea what search parameters to use, so excuse me if this has already been discussed somewhere!

    I've got the following problem: I have a file that contains the following (example) data:

    Manufacturer;Model;2007;Signal_Name;640;2;0;Tester ;0
    Another_Manufacturer;Some_Model;2007;Signal2_Name; 756;4;0;Some_Tester;0
    etc.
    As you can see it's a ;-seperated file that contains signal information. Every new line in the file represents a new signal.
    The final '0' on the line indicates the signal isn't processed yet (i.e. added to our signal database).

    Now, what I need to do is, when the signal has been processed, replace that '0' with a '1'. I think this should be doable with pointers, but apparently I have too little knowledge about pointers to make this work.

    Here's an example of what I thought is a solution - please note I know this example is 90% bollocks, it's a "road plan" rather than a code example:

    Code:
       
       FILE *fpin;
       int signals_cnt=0;
    
        if((fpin = fopen(signal_file,"r+"))!=NULL)
        {
           while(fpin!=EOF)
           {
              fpin++;
              puts(fpin);
              if(fpin=='\n')
              {
                 signals_cnt++;
                 if(signals_cnt==processed_signal_number)
                 {
                     fpin--;
                     fpin='1';
                 }
    
              }
    
           } //  while(fpin!=EOF)
    
        }
    So the idea is to check for a new line character to count the signal number, and when the desired signal number was found, change the 0 into 1.
    Apparantly fpin (declared as a FILE type) doesn't like being played with (the fpin++ results in blabla on-screen).

    Hope it's clear :S Any help would be greatly appreciated!

    Thanks in advance, René
    Last edited by rkooij; 05-09-2007 at 08:29 AM.
    http://www.f1rstracing.nl/
    OS: Windows XP
    Compiler: Dev-C++

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM