Thread: Reading a text file

  1. #1
    zach
    Guest

    Reading a text file

    Code:
    fscanf(fle5,"%[^\n]%*c", dummy);
    This code is supposed to be able to deal with spaces in the text file, which it does, BUT the code causes skipping lines, which is not what I want. (So there seems to be a \n to be got rid of.) The code is also supposed to break at EOF which it doesn't, but which it should.

    Please advise. Thank you.
    Last edited by zach; 09-27-2019 at 09:53 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,176
    Well it rather depends what other file reading functions have already happened.

    Normally, I would suggest just using fgets() to read each line, then use sscanf (or any other string processing functions) to parse the data in memory.

    Mixing input styles almost always results in confusion.

    > The code is also supposed to break at EOF which it doesn't, but which it should.
    You never asked it to.
    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.

  3. #3
    zach
    Guest
    Quote Originally Posted by Salem View Post
    Well it rather depends what other file reading functions have already happened.

    <snipped >
    Yes!! Thank you. Zach K.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading text file
    By Haris1 in forum C++ Programming
    Replies: 4
    Last Post: 09-26-2012, 07:09 AM
  2. Reading a text file
    By DeanWinchester in forum C Programming
    Replies: 53
    Last Post: 12-25-2011, 04:45 PM
  3. Replies: 8
    Last Post: 05-05-2010, 02:43 PM
  4. reading from a text file.
    By rox in forum C++ Programming
    Replies: 3
    Last Post: 03-12-2004, 02:22 AM
  5. Reading Text File
    By NavyBlue in forum C Programming
    Replies: 4
    Last Post: 01-31-2003, 10:25 AM

Tags for this Thread