fseek question

This is a discussion on fseek question within the C Programming forums, part of the General Programming Boards category; Ok as i had posted earlier on a test thing for multiple choice. Lets say the user get a question ...

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

    Question fseek question

    Ok as i had posted earlier on a test thing for multiple choice. Lets say the user get a question wrong, i was lookin up fseek. Could i actually use fseek to go to that specific question they got wrong. May i store the number of the questions they got wrong in an array, and use fseek to look up those wrong answers. Just a question if it cant just let me know, if yea how would u go about doin it?

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Yep. Just use fseek() with the offset from the beginning of the file (which can be retrieved using ftell()), and you can skip to arbitrary points in the file. I used fseek() in the example I gave to you earlier too.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    Quote Originally Posted by master5001 View Post
    Yep. Just use fseek() with the offset from the beginning of the file (which can be retrieved using ftell()), and you can skip to arbitrary points in the file. I used fseek() in the example I gave to you earlier too.

    O my mats really, ill really have to go over ur codes tonight and understand it well. I found an open skeleton of a quiz program the other day and posted it here lol, i didnt have no knowledge on C no one answered and so i started reading immediately. Its a very interestin langugage

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    If you had left your previous code on the one thread I could have told you where those would have been appropriate. Can you just repost the code here?

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    Quote Originally Posted by master5001 View Post
    If you had left your previous code on the one thread I could have told you where those would have been appropriate. Can you just repost the code here?
    Ok sure mats, this is the code identation and everthing is strayed off since its a rough draft as yet: here it is:
    Last edited by blondie.365; 10-20-2008 at 03:45 PM.

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Matt*

    Mats is the British guy who is always helpful. I am the Californian guy who is often... less than helpful. I will review the code real quick. Hold on.

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    Quote Originally Posted by master5001 View Post
    Matt*

    Mats is the British guy who is always helpful. I am the Californian guy who is often... less than helpful. I will review the code real quick. Hold on.
    Oh my, lol, k ur Californian got it!

  8. #8
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by blondie.365 View Post
    Oh my, lol, k ur Californian got it!
    Lol! The point was spell my name right Not locality.

    Ok, what you *could* do is make an array and use that array to keep track of the wrongs.
    Last edited by master5001; 10-20-2008 at 03:47 PM.

  9. #9
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    Quote Originally Posted by master5001 View Post
    [code]
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    #include <stdlib.h>


    Ok.. so that is just a fixed up version of your code as-is. There are some issues with it that are important to realize. You are not keeping track of wrong answers at all. You should probably just exit the program if you cannot open the question file. And you never did check if tempfile was NULL or not.
    Oh ok i thanks i got it. what about the fseek,lol, how would it be implemented?

  10. #10
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    Quote Originally Posted by master5001 View Post
    Lol! The point was spell my name right Not locality.

    Ok, what you *could* do is make an array and use that array to keep track of the wrongs.
    jaja ok got it too now, yea i was on that way of thinking, thanks i thnk ill be able to solve it with couple of reading ours and so, then fseek it right, would that be correct

  11. #11
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Yeah I am just trying to screw with your current code is little as possible. I am putting things in color coding so its easier to see where I am editing and making changes.

  12. #12
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    Quote Originally Posted by master5001 View Post
    Yeah I am just trying to screw with your current code is little as possible. I am putting things in color coding so its easier to see where I am editing and making changes.
    Oh ok,will be here

  13. #13
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    The part in green may need to be moved. They will otherwise get called everytime the wrong answer loop is called. I didn't *finish* up what needs to be done in the inner most loop because that robs you the joy of figuring out what to do when you place the the file in the right position.

  14. #14
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    Quote Originally Posted by master5001 View Post
    The part in green may need to be moved. They will otherwise get called everytime the wrong answer loop is called. I didn't *finish* up what needs to be done in the inner most loop because that robs you the joy of figuring out what to do when you place the the file in the right position.
    Thank you very much, im sure i can finish the rest. I really appreciate all the help today, its been greatly appreciated to the maximum.

    Sorry but i have a favor to ask if its doable, id just like to ask u if the codes could be removed. For as i said we could get penalized, if its possible please, if its not i understand. But still thank you very much!!

  15. #15
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    What codes?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fseek failing - Error: Invalid argument
    By avi2886 in forum C Programming
    Replies: 14
    Last Post: 05-14-2009, 08:49 PM
  2. fseek() changing an unrelated variable?
    By aaronvegh in forum C Programming
    Replies: 3
    Last Post: 11-21-2007, 01:30 PM
  3. fseek high cpu usage?
    By chunlee in forum C Programming
    Replies: 2
    Last Post: 02-19-2005, 06:27 AM
  4. popen and fseek
    By mach5 in forum C Programming
    Replies: 4
    Last Post: 11-29-2003, 01:03 AM
  5. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21