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

read file n spot blank char n re write file witout extra blank

Discussion in 'C++' started by dev1910, Dec 8, 2007.

  1. dev1910

    dev1910 New Member

    Joined:
    Dec 8, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi frenz,
    I am having problem with reading fileand rewrite the file topic. As part of my project , i need to write a program that reads text from one file and writes an edited version of the same text to another file. The edited version is identical to the unedited version except that every string of two or more consecutive blanks is replaced by a single blank. Thus, the text is edited to remove any extra blank characters.

    Plz someone helpin me with syntax as i dunno how to read blank char frm file n omit extra blank char...
     
  2. HowardL

    HowardL New Member

    Joined:
    Aug 5, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    East Coast USA
    Well first you need to be able to:
    - Open two files,, one for reading and another for writing.
    http://www.cplusplus.com/reference/iostream/ifstream/open.html
    http://www.cplusplus.com/reference/iostream/ofstream/open.html

    - Read one character at a time from the infile.
    http://www.cplusplus.com/reference/iostream/istream/get.html

    - Process that character to determine if it is a second, third, etc. space.
    If yes write it, if no get the next character.
    A space can be identified by the ascii value 0x20 or you can also use ' ' as in:
    if( c == 0x20 ) . . . or . . . if( c == ' ' ) ...both are equivilent.

    - Write desired characters to the outfile.
    http://www.cplusplus.com/reference/iostream/ostream/put.html

    - Finally you will need to close the files (see open.html's above)
     

Share This Page