1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Locating end of text file

  1. May 20, 2010 #1
    i am trying to locate the end of a text file and delete any extra white spaces following it, but i am having trouble trying to do this. is there an easy way to do this? right now i am reading the text in character by character and outputting the text to another outstream file. i can't seem to locate the end of the file and delete trailing blanks. also, i am having trouble locating the beginning of a new line in my outstream file. i also need to delete leading white spaces. any help would be appreciated.
     
  2. jcsd
  3. May 20, 2010 #2

    CompuChip

    User Avatar
    Science Advisor
    Homework Helper

    Well, it may help if you post some code.
    First of all you are not telling us which programming language you are using, and second of all, I can think of dozens of ways to read and write files (about three of them in C++ alone, off the top of my head).
     
  4. May 20, 2010 #3
    i am using instream & outstream and c strings.

    for the end of the file part i would do some thing like
    Code (Text):
    if (inf.eof())
    { outf << "\n";
    if (isspace(c))
    !inf.get(c);
    }
    doesn't work the way i wish it did.. i am having trouble actually finding the beginning and end of new lines
     
  5. May 20, 2010 #4

    Mark44

    Staff: Mentor

    Why are you attempting to read characters after you've reached the end of the file? eof() returns true (actually a nonzero value) when there are no more data left in the input stream.
     
  6. May 20, 2010 #5

    CompuChip

    User Avatar
    Science Advisor
    Homework Helper

    Apart from the fact that a statement like
    !inf.get(c) ​
    does not really make sense on its own.

    Please don't take offense, but I am curious: did you ever program (C(++)) before?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook