Thread: Need help on Reading from a file

  1. #91
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by lifeis2evil View Post
    I've never seen sprintf befores >_<
    http://msdn2.microsoft.com/en-us/lib...1k(VS.80).aspx
    Include stdio.h to use it. But don't focus on it now. Focus on getting your cout and precision to work instead.

  2. #92
    Registered User lifeis2evil's Avatar
    Join Date
    Oct 2007
    Posts
    76
    --
    Last edited by lifeis2evil; 10-25-2007 at 04:09 PM.

  3. #93
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, I think that's alright. So have you tested it yet?

  4. #94
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> I am sure I have it in the wrong spot, should it be in the if / else ?

    I would put it immediately before the cout call that needs to be affected by the maipulators. In this case, those cout calls are inside the if/else if. It can work where you have it if you fix the one small error you have left, but it might make more sense to the reader (and you) to keep it close to the place that is affected.

  5. #95
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Seeing as there's only one call to cout and two IFs, I don't see why you can't put it before the IFs, where it's right now. It shouldn't hurt.

  6. #96
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    It shouldn't hurt, I just think it makes more sense (especially from a novice programmer's point of view) to put it next to the places in the code that use.

  7. #97
    Registered User lifeis2evil's Avatar
    Join Date
    Oct 2007
    Posts
    76
    --
    Last edited by lifeis2evil; 10-25-2007 at 04:08 PM.

  8. #98
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Alright, good grief. Good work.
    Now you can experiment with sprintf_s is you want Or you could just go to bed and get some sleep! Like me!

  9. #99
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Well done.

    The last thing you should do is fix up your indentation a bit. It will make it easier for the grader to read the program, and easier for you and others to go back and see what's going on. Plus, it's a good habit to get into (although really the indentation should be kept properly from the beginning).

  10. #100
    Registered User lifeis2evil's Avatar
    Join Date
    Oct 2007
    Posts
    76
    ---
    Last edited by lifeis2evil; 10-25-2007 at 04:08 PM.

  11. #101
    Registered User lifeis2evil's Avatar
    Join Date
    Oct 2007
    Posts
    76
    haha I definitely neeeed sleep or else I think I could possibly pass out lol ..well not really my eyes just hurt and are watery and I still have to do the chart thing but I'll do it tomorrow morning cause I think I have all day tomorrow to submit hopefully

  12. #102
    Registered User lifeis2evil's Avatar
    Join Date
    Oct 2007
    Posts
    76
    --
    Last edited by lifeis2evil; 10-25-2007 at 04:08 PM.

  13. #103
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I like the first better. It makes it clearer when you've forgotten or decided not to initialize a variable.

    In general, though, it is better to declare variables only when you are ready to use them. That would mean many of those variables would be declared lower in the code. In your case, however, it is not worth it for you to try and make that change to this assignment.

  14. #104
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> show_gender = '\0'
    That just initializes show_gender to the null character. \0 is an escape sequence. It just represents a character that can't be displayed normally.

    Since initializing variables is always good practice, Elysia just picked a character to initialize with. Any character will work, but the null character is the default value for a char so it might make more sense. It turns out in this case that it doesn't matter what it is, the code will execute the same regardless. You could even leave it uninitialized, since the first time it is used it will be given a value.

  15. #105
    Registered User lifeis2evil's Avatar
    Join Date
    Oct 2007
    Posts
    76
    Quote Originally Posted by Daved View Post
    I like the first better. It makes it clearer when you've forgotten or decided not to initialize a variable.

    In general, though, it is better to declare variables only when you are ready to use them. That would mean many of those variables would be declared lower in the code. In your case, however, it is not worth it for you to try and make that change to this assignment.
    Oh really, my teacher always declares everything 1st and then does everything else hehe. Okay gonna recheck all my code ad fix it up. And yeah I haven't learned Null yet

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. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM