Thread: fget question

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    19

    fget question

    hi guys,

    char mystring [100];
    fget(mystring , 50, myFile);

    does it means that i can only read 100 words from a myFile? what if myFile consist of alot of words and cant be determined?

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you will use a loop
    Code:
    while(fgets(mystring,sizeof mystring, myfile))
    {
       /*process mystring buffer */
    }
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    19
    yea but i already declared mystring to an array size of 100. does dat makes any difference?

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by norhos View Post
    yea but i already declared mystring to an array size of 100. does dat makes any difference?
    What difference?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    19
    doesnt it means dat the max number of words will be set to 100? im confuse now lol

  6. #6
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by norhos View Post
    doesnt it means dat the max number of words will be set to 100? im confuse now lol
    no it doesn't - it does nothing to do with words count

    100 - is how many chars (letters) you are reading from the file AT ONCE. doing it in a loop gives you a possibility read all the file
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  7. #7
    Registered User
    Join Date
    Mar 2008
    Posts
    19
    ic thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM