Results 1 to 11 of 11

Thread: C++ question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Time Lord Member The_Doctor's Avatar
    Join Date
    Oct 2004
    Location
    The TARDIS
    Posts
    2,040

    Default Re: C++ question

    I think I have solved the problem by using the atoi() thing.

  2. #2
    Time Lord Member The_Doctor's Avatar
    Join Date
    Oct 2004
    Location
    The TARDIS
    Posts
    2,040

    Default Re: C++ question

    I have got it all working now.

  3. #3
    zombologist Senior Member doc_bean's Avatar
    Join Date
    Oct 2004
    Location
    Riding Shai-Hulud
    Posts
    5,346

    Default Re: C++ question

    How did you do it ? I've been messing around with the getline() thing too, but it's not really convienent for loading in tables or matrices.
    Yes, Iraq is peaceful. Go to sleep now. - Adrian II

  4. #4

    Default Re: C++ question

    Use strtol() instead of atoi(). atoi() doesn't detect, or return, certain kind of errors. strtol() does, AND it has more functionality (bases, etc).
    And it has its variants, as well, strtod(), strtoll(), strtoul()...
    Therapy helps, but screaming obscenities is cheaper.

  5. #5
    Mafia Hunter Member Kommodus's Avatar
    Join Date
    Mar 2004
    Location
    In a top-secret lab planning world domination
    Posts
    1,286

    Default Re: C++ question

    Ultimately, I think you'll want to use something other than a text file for this application. A text file will do the job, but as you get more programming knowledge you'll be able to use:

    1. A binary file containing records (I think this is what most games do)
    2. A database of some kind, such as MySQL

    I haven't used C++ in a while (mainly C# these days), so I won't try to explain either, but don't worry: it'll come. Neither is all that hard.
    If you define cowardice as running away at the first sign of danger, screaming and tripping and begging for mercy, then yes, Mr. Brave man, I guess I'm a coward. -Jack Handey

  6. #6
    Time Lord Member The_Doctor's Avatar
    Join Date
    Oct 2004
    Location
    The TARDIS
    Posts
    2,040

    Default Re: C++ question

    How did you do it ?
    The numbers in the text file where like this:
    1|2|3|4|5|6|7|8|9|10

    To extract a number I used:
    HighScoresfile.getline(buf1, 1024, "|");

    buf1 was a char array with 1024 places.

    Then I copied the contents of the array into an int called HS1:
    HS1 = atoi(buf1);

    Then I repeated the it, only with the buf and HS number increasing until it got to 10.

    I have feeling that this is not the best way to do it, but we have not been taught how to do stuff with files yet. It works, so I am pleased with myself.

    Ultimately, I think you'll want to use something other than a text file for this application. A text file will do the job, but as you get more programming knowledge you'll be able to use:

    1. A binary file containing records (I think this is what most games do)
    2. A database of some kind, such as MySQL
    We will probably be doing this stuff next year.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Single Sign On provided by vBSSO