Thread: Can't get fgets to work properly

  1. #16
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by lonkz View Post
    I tried initialising the stream in the main method just once before calling any functions and that results in only one anagram being printed. This caused me to draw the assumption that every time I run the dictionary file through (ie. call the checkDict function) and either find something or not I need to reinitialise the file stream in order for it to begin from the very top again.
    Am I wrong in believing this?
    You need to reinitialize the file stream, yes. The function to do that is not fopen -- it is rewind.

  2. #17
    Registered User
    Join Date
    Nov 2008
    Posts
    10
    Thank you tabstop. That seems to do the trick.
    I never knew about the rewind function. Guess I didn't do my homework... for shame!

    Anyways it works perfectly every time now and even a little faster with rewind(). Still kind of slow though, so I was wondering if there was anything to be done to increase the speed. I'm still not sure if a recursive function is the best way and there may be other things that can be improved significantly. The time it takes the program to execute grows ( not suprisingly ) eksponentially with longer strings. I am not sure if this is the correct place to ask this but any further help regarding optimization would be greatly appreciated.

  3. #18
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    You could read the file only once and store the dictioanary in an array.
    checkDict() could operate on that array.
    Kurt

  4. #19
    Registered User
    Join Date
    Nov 2008
    Posts
    10
    Great idea Kurt. I'm not totally down with two-dimensional arrays but I'll read up on it and give it a shot soon.
    Edit: By the way Kurt, would some sort of hash set be preferrable to an array or would it even work and would it be faster than reading lines from a file stream?

    I've been toying around with adding a couple of extra features and was wondering if it was possible to make some sort of indication that the application is running and not just stalled or waiting. Maybe something like an animation of three dots incrementing . . .
    Another way could be the - \ | / - \ | - \ | /- thingie where a dash seems to be rotating.

    I've been googling my fingers off but the answer seems to elude me.
    Last edited by lonkz; 01-03-2009 at 02:53 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 11-17-2008, 12:36 PM
  2. How properly inherit from template?
    By 6tr6tr in forum C++ Programming
    Replies: 118
    Last Post: 04-25-2008, 04:30 AM
  3. My monitor doesn't work with Ubuntu Linux.
    By indigo0086 in forum Tech Board
    Replies: 1
    Last Post: 07-12-2007, 10:59 AM
  4. fgets erroneoulsy returns null string
    By leonv in forum C Programming
    Replies: 3
    Last Post: 12-04-2006, 06:20 AM
  5. how fgets work ??
    By Nada in forum C Programming
    Replies: 1
    Last Post: 12-22-2001, 06:07 PM