1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Certain characters read from file and save in new file

Discussion in 'C' started by meyup, Jun 13, 2010.

  1. meyup

    meyup New Member

    Joined:
    Feb 15, 2010
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    I, an absolute beginner C need urgently a code to create the following program:
    it is to read only certain characters (eg 10-300) of a binary file and save it to a new file.
    Can anyone help me?
     
  2. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    very simple you use a loop in which you fgetc reads with individual characters. You control whether the character is just what you want and write that in the other file.
     
  3. meyup

    meyup New Member

    Joined:
    Feb 15, 2010
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    Is it possible to read many thousands of characters?

    Please post once a sample source code, as I said, I am a complete beginner ...
     
  4. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    You can read many so theoretically infinite

    Code:
    for(int c = 0; (c = fgetc (file)) = EOF;) 
    ( 
       if(c> = 10 & & c <= 300) 
         fputc (c, outfile); 
    )
     
  5. meyup

    meyup New Member

    Joined:
    Feb 15, 2010
    Messages:
    102
    Likes Received:
    0
    Trophy Points:
    0
    And why only in theory?
     
  6. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    because the memory and the lifetime of computers are finite
     

Share This Page