Thread: reading in from a file

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    12

    reading in from a file

    I am trying to read a file into a string, but it keeps only reading one line of the file. Here is my read code:

    Code:
        for(status = fgets(filebuff, MAX_LINE, inp); status != 0;
           status = fgets(filebuff, MAX_LINE, inp)){
         }
    MAX_LINE is 10240, and I am not sure if that is good, bad or indifferent. If there is a better way to read in from a file, please let me know. Thanks for the help

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    12
    Oh, and I am also using calloc to allocate the array size before I read in from the file.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You are reading line by line, overwriting the same buffer each time. What you do next depends on what you want to do with the data.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

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. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM