Thread: File I/O (white-space)

  1. #1
    Registered User
    Join Date
    Oct 2001

    Question File I/O (white-space)

    I am wondering how can i erase white space.
    If program read data from source file then write it on the target file. If there are leading and trailing white-space in the source file but should be discarded for the destination file.

  2. #2
    Registered User
    Join Date
    Oct 2001


    I'm doing something similar. You'll have to build ur write string one character at a time. Use two counters. If you see double/reoccuring spaces, you just skip to the next character in the read string, but maintain the same position in the write string.

    When you write a character into the new string, increase the second counter.

    Hope that helped.

  3. #3
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    //Open a stream
    	ifstream file;
    //Open file"file.txt", ios::in);
    //Read data
    	   file.get(x); //Get the data by char
    	   if(x==' ') //x is a space
                        //Do nothing
                        //handle file
    This is taking in every char x; and checking for spaces.
    C++ Is Powerful
    I use C++
    There fore I am Powerful

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  4. White space problems in file input
    By cxs00u in forum C++ Programming
    Replies: 4
    Last Post: 03-20-2002, 11:06 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM