Thread: Need help in writing a function or any of the sort!

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    46

    Question Need help in writing a function or any of the sort!

    Ok i know i had posted something on this about two days ago. However, time passed and and i . I tried several things, fseek and temporary files but none with success. Matt dnt worry u dnt have to answer this one. I know im new to the language and its a bit confusing. I'll get straight to the point, can anyone give me tips on how to go about doing this. Im reading data from a file in this format:
    Last edited by blondie.365; 10-22-2008 at 06:22 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Right away or at the end of the whole list?

    Right away, you can use a loop -- keep asking until they hit upon the right answer.

    At the end of the list, you'll have to keep track in some piece of data somewhere which ones they missed, and you can use that to re-read the appropriate questions.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    Quote Originally Posted by tabstop View Post
    Right away or at the end of the whole list?

    Right away, you can use a loop -- keep asking until they hit upon the right answer.

    At the end of the list, you'll have to keep track in some piece of data somewhere which ones they missed, and you can use that to re-read the appropriate questions.

    i wanted it at the end of the first test, like after the end if they got wrongs do over the wrong questions. Im so confused.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So you'll have to keep track of previous results. You could keep track of right answers, or wrong answers, or the answers given, or score, or ... well anything really that will allow you to recreate, later, whether this question was answered correctly or not the first time.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    Quote Originally Posted by tabstop View Post
    So you'll have to keep track of previous results. You could keep track of right answers, or wrong answers, or the answers given, or score, or ... well anything really that will allow you to recreate, later, whether this question was answered correctly or not the first time.
    Ok, say i keep track of the wrong questions number. My question wud be how to go back to that exact same location of the text file

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Code:
    char throwaway[255]; //or some large number
    for (i = 0; i < wrong_question_number; i++) {
        fgets(throwaway, sizeof throwaway, file);
    }
    You will have to use rewind() to get back to the beginning of the file.

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    Quote Originally Posted by tabstop View Post
    Code:
    char throwaway[255]; //or some large number
    for (i = 0; i < wrong_question_number; i++) {
        fgets(throwaway, sizeof throwaway, file);
    }
    You will have to use rewind() to get back to the beginning of the file.

    I understand the rewing and everything, but wouldnt that start reading from the begning of the file. What if number one was correct and number three wrong. I'd have to skip those, how would i really go to number three?

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Read number one and throw it away (hence the name), read number two and throw it away.

    (Edit: I suppose if you don't like that idea you can get really fancy with fgetpos and fsetpos.)

  9. #9
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    Quote Originally Posted by tabstop View Post
    Read number one and throw it away (hence the name), read number two and throw it away.

    (Edit: I suppose if you don't like that idea you can get really fancy with fgetpos and fsetpos.)
    Sorry tabstop, im a bit confused: would this char throwaway[255]; //or some large number
    actually be the array holding the wrong numbers, their indexes?

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Not in any way, shape, or form. Did you read the other line of code in my example? Did you recognize it, since I blatantly stole it from your program? What does it do there, and what will it do here?

  11. #11
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    Quote Originally Posted by tabstop View Post
    Not in any way, shape, or form. Did you read the other line of code in my example? Did you recognize it, since I blatantly stole it from your program? What does it do there, and what will it do here?
    Code:
    for (i = 0; i < wrong_question_number; i++) {
        fgets(throwaway, sizeof throwaway, file);
    }

    I understand from this that once it has more than zero wrongs it will go into this loop, and get sentences from the file, however the throwaway is that im not really comprehending. U say it tosses the correct ones, but how?? puzzled :/

  12. #12
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Hmmmmm why did you not copy the code that you had me delete? It wouldn't have been stealing rather it was more like collaborating. Since we worked through the whole problem together.

  13. #13
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    Quote Originally Posted by master5001 View Post
    Hmmmmm why did you not copy the code that you had me delete? It wouldn't have been stealing rather it was more like collaborating. Since we worked through the whole problem together.
    Hey Matt

    Are u referring to the first thread, that had malloc, and pointers on structures?

  14. #14
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by blondie.365 View Post
    Code:
    for (i = 0; i < wrong_question_number; i++) {
        fgets(throwaway, sizeof throwaway, file);
    }

    I understand from this that once it has more than zero wrongs it will go into this loop, and get sentences from the file, however the throwaway is that im not really comprehending. U say it tosses the correct ones, but how?? puzzled :/
    It puts them somewhere, and then you overwrite it with the next one, so it's gone!

  15. #15
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Actually I am refering to the thread about fseek().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using own function in writing a function
    By behzad_shabani in forum C Programming
    Replies: 4
    Last Post: 06-02-2008, 09:22 AM
  2. Very slow file writing of 'fwrite' function in C
    By scho in forum C Programming
    Replies: 6
    Last Post: 08-03-2006, 02:16 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM