end of line in text file

This is a discussion on end of line in text file within the C Programming forums, part of the General Programming Boards category; While reading a text file, Is there a way to directly reach the end of line in a text file....? ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    13

    end of line in text file

    While reading a text file,
    Is there a way to directly reach the end of line in a text file....? using fseek or some other function ?
    Is '\n' a standard to look for the end of the line?

    Are the delimiters(\n, \t, \l, \0) used differently for different kind of text files ?
    e.g., for html file, doc file, txt file....

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,336
    > Is there a way to directly reach the end of line in a text file....?
    Only by using fgets(), and that actually reads the newline rather than stopping at the newline.

    > Is '\n' a standard to look for the end of the line?
    Yes, if you use fopen()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,159
    Quote Originally Posted by Salem
    > Is '\n' a standard to look for the end of the line?
    Yes, if you use fopen()
    ...without the 'b' in the mode string (i.e. "r" instead of "rb")
    If you understand what you're doing, you're not learning anything.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    using fseek
    Not using fseek, since you shouldn't use it in text mode. Simply read characters until you find the newline character. Or you could simply call fgets in a similar fashion.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User Jaqui's Avatar
    Join Date
    Feb 2005
    Posts
    416
    don't forget, \n is newline and carriage return in macos, and *x.
    in an ascii dos text there is also the \r for the carriage return to get back to left side of screen.
    it can be important, when displaying the contents.. people would be wondering what the \r was from.
    Quote Originally Posted by Jeff Henager
    If the average user can put a CD in and boot the system and follow the prompts, he can install and use Linux. If he can't do that simple task, he doesn't need to be around technology.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,336
    > in an ascii dos text there is also the \r for the carriage return to get back to left side of screen
    Which is why the standard routines map \x\y\z or whatever the native convention for the OS is into a standard \n.
    Then you don't have to worry about it anymore, and you just stick to \n
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple C App to add line breaks to a text file
    By sari in forum C Programming
    Replies: 2
    Last Post: 07-09-2009, 10:45 PM
  2. help again with scrolling without wrapping
    By Dukefrukem in forum C Programming
    Replies: 8
    Last Post: 09-21-2007, 12:48 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Replies: 3
    Last Post: 04-27-2005, 11:50 AM
  5. how to check for end of line in a text file
    By anooj123 in forum C++ Programming
    Replies: 6
    Last Post: 10-24-2002, 11:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21