Thread: Help with some binary issues

  1. #16
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    Code:
    cin >> binary[7];
    //should be
    cin >> binary;
    edit: but with a buffer size of 8 you can only type a string 7 chars long. the 8th is reserved for null-termination character.

    edit: another question. Have you covered any loop structures. do-while, while, or for?
    Last edited by Raigne; 10-13-2008 at 12:58 AM.

  2. #17
    Registered User
    Join Date
    Oct 2008
    Posts
    10
    I think the if/else if statement could work but would be an extremely round about way to get there, though. Probably what my instructor wants... But I'm still getting the same error message: Stack around the variable 'binary' was corrupted.
    Is the for statement the only way to get around that?

  3. #18
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    The error message is because to are typing to much data for the array.

    If you have
    Code:
    char binary[7];
    You are only able to use
    binary[0]
    binary[1]
    binary[2]
    binary[3]
    binary[4]
    binary[5]

    binary[6] much be empty for the '\0' null-termination character.

    This i believe is called a buffer over-run.

  4. #19
    Registered User
    Join Date
    Oct 2008
    Posts
    10
    Oh, so that's what the book meant then. It works now that I extended the boundary of the char. Thanks so much Raigne. But I think I prefer your method. It's much neater. Now that means more time spend to finish the rest of my homework. But thanks again Raigne.

  5. #20
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    Anytime. Best of luck to you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 09-30-2008, 12:10 AM
  2. Binary Converter - Various stupid string issues :p
    By polarpete in forum C++ Programming
    Replies: 7
    Last Post: 08-21-2005, 02:46 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM