Thread: Reading an entire File

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    22

    Reading an entire File

    Hi, is there anyway to read an entire file and print in on screen? file consists of strings and integers!

  2. #2
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    Yes, fgets.
    Code:
    while(!asleep) {
       sheep++;
    }

  3. #3
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    There are examples on the bottom of these pages:

    fgetc
    fgetc, fgetwc, _fgetchar, _fgetwchar (CRT)

    fread (which would be better for those structs you have been working on)
    fread (CRT)
    Fact - Beethoven wrote his first symphony in C

  4. #4
    Registered User
    Join Date
    Feb 2013
    Posts
    22
    hey thanks for the info but im still not sure how to use it :/ would the fgetc allow me to search the file and sort it ??

  5. #5
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    What I can gather from you is that you want to sort the structs which you created in the other thread.

    What you need to do is use a linked-list. The title of your other thread did have the word "linked-list", but you never ended up actually doing a linked list.

    The way you need to go forward with your program (in my opinion) is to forget about saving the data until you can put it in a linked list. Once you are there, you can search and sort very easily.
    Fact - Beethoven wrote his first symphony in C

  6. #6
    Registered User
    Join Date
    Feb 2013
    Posts
    22
    well that was my plan fro the beginning! but i have no idea how to start a linked list! help!!

  7. #7
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294
    I would start here: Linked Lists in C Tutorial - Cprogramming.com

    Post any questions you may have.

  8. #8
    Registered User
    Join Date
    Feb 2013
    Posts
    22
    Thanks alot for all the help guys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-21-2012, 04:07 PM
  2. C++: Output An Entire Text File- Can It Be Done?
    By lusciousleanne in forum C++ Programming
    Replies: 6
    Last Post: 01-30-2008, 09:27 AM
  3. Parse function not reading through entire vector
    By jmd15 in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2007, 04:30 PM
  4. reading entire file into a class
    By linucksrox in forum C++ Programming
    Replies: 2
    Last Post: 12-12-2005, 10:52 AM
  5. entire file
    By linuxdude in forum C Programming
    Replies: 30
    Last Post: 02-23-2004, 06:06 PM