Thread: Suggestions on a bit of FILE I/O anyone??

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    As noted in the comment that you opted not to read.

    [edit]Oh wait... Nevermind. That was probably blanketed over to me, but definitely directed at the OP. Sorry[/edit]

    In my code, you would simply do something like this:

    Code:
        char *p; // <--= declare this somewhere
    
        if((p = strtok(buffer, ";")))
          strncpy(array->quest, p, sizeof(array->quest));
        else
          *array->quest = 0;
    
        for(i = 0; i < 4; ++i)
          if((p = strtok(NULL, ";")))
            strncpy(array->choice[i], p, sizeof(*array->choice));
          else
            *array->choice[i] = 0;
    
        if((p = strtok(NULL, ";")))
          array->ans = *p
        else
          array->ans = 0;
    Last edited by master5001; 10-20-2008 at 12:47 PM.

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    Quote Originally Posted by master5001 View Post
    As noted in the comment that you opted not to read.

    [edit]Oh wait... Nevermind. That was probably blanketed over to me, but definitely directed at the OP. Sorry[/edit]

    In my code, you would simply do something like this:

    Code:
        char *p; // <--= declare this somewhere
    
        if((p = strtok(buffer, ";")))
          strncpy(array->quest, p, sizeof(array->quest));
        else
          *array->quest = 0;
    
        for(i = 0; i < 4; ++i)
          if((p = strtok(NULL, ";")))
            strncpy(array->choice[i], p, sizeof(*array->choice));
          else
            *array->choice[i] = 0;
    
        if((p = strtok(NULL, ";")))
          array->ans = *p
        else
          array->ans = 0;
    Lol, hey anyway i think the best way might be for me to go and read over structures cause im kinda new to them, hence, the code above bit confusing lol

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by blondie.365 View Post
    Lol, hey anyway i think the best way might be for me to go and read over structures cause im kinda new to them, hence, the code above bit confusing lol
    Just refer to my last post. I think that does it better than how you are trying to do it (alas, I had to break down and actually read your code).

    I think it would be more interesting to lose the hard-coded A, B, C, and D's as well as the hard coded question numbers. By doing that, you could totally have random order to the question as well as mix up the answers.

    [question-id];[question];[answer-id];[answer];[answer-id];[answer];[answer-id];[answer];[answer-id];[answer];[correct-answer-id];
    Last edited by master5001; 10-20-2008 at 01:04 PM.

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    Quote Originally Posted by master5001 View Post
    Just refer to my last post. I think that does it better than how you are trying to do it (alas, I had to break down and actually read your code).

    I think it would be more interesting to lose the hard-coded A, B, C, and D's as well as the hard coded question numbers. By doing that, you could totally have random order to the question as well as mix up the answers.

    [question-id];[question];[answer-id];[answer];[answer-id];[answer];[answer-id];[answer];[answer-id];[answer];[correct-answer-id];
    Hey Master5001 thanks for the insight on structures like i said ill go home and read on it, ill look at your codes maybe change my entire way im doin the coding and start over from scrtach cuz i thnk the way it is is a bit wordy and unecessary, yea as u can see its a quiz im trying to do. Has one question and four possible answers. Thank you for your time, hopefully this program is done by wednesday, lol

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    46
    Quote Originally Posted by master5001 View Post
    Just refer to my last post. I think that does it better than how you are trying to do it (alas, I had to break down and actually read your code).

    I think it would be more interesting to lose the hard-coded A, B, C, and D's as well as the hard coded question numbers. By doing that, you could totally have random order to the question as well as mix up the answers.

    [question-id];[question];[answer-id];[answer];[answer-id];[answer];[answer-id];[answer];[answer-id];[answer];[correct-answer-id];
    Hey Master5001 by the way u said refer to my last post, did that mean u posted on something similar to this, if u did how do i go to it. I tried clickin on ur user name but it said i dnt have privilges to view or soemthing like that.

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by blondie.365 View Post
    Hey Master5001 by the way u said refer to my last post, did that mean u posted on something similar to this, if u did how do i go to it. I tried clickin on ur user name but it said i dnt have privilges to view or soemthing like that.
    I was saying refer to this post. You need to post like 10 times to be able to have that privilege, I believe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Question about file I/O from a newbie
    By henrik in forum C Programming
    Replies: 4
    Last Post: 11-13-2007, 12:48 AM
  3. File I/O Question
    By Achy in forum C Programming
    Replies: 2
    Last Post: 11-18-2005, 12:09 AM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. Replies: 3
    Last Post: 03-04-2005, 02:46 PM