Thread: I'm getting confused on the strings...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    My stupid strings aren't working...

    Alrighty, I know a ton about strings from Game Maker. But I don't know how long a string[256] is. How many letters can fit in that?
    Last edited by Rune Hunter; 08-22-2004 at 09:50 AM.

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    if it is:
    Code:
    char string[256];
    It can hold 255 characters and a null character.

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    alright making sure there thanks!

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Here is the code...


    Code:
        {
            char answera[1];
            char answerb[1];
            char answerc[1];
            cout<<"Here is the test...\n\n\n";
            getch();
            cout<<"question 1...\n\nWhat does blah blah mean?\n\nA. Start blah blah not importent.\nB. or answer 2.\n";
            cin.getline(answera, 1, '\n');
            cout<<"your answer was:"<<endl<<answera;
            getch();
            mainmenu=1;
        }

    whats wrong?

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    The fact that you are using a value of 1 for the array size. If it is to be a string then it has to have a null terminating character which means you have no room for the actual answer.

    If you just want a character then just use a char instead of trying to hack it with a string.

  6. #6
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    uhh yes I see. I thought about nto using a string but I wanted to learn how actauly c++ strings work. But now that I do I am oging to use no string.

    Thanks a ton again!!!!!

  7. #7
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Well you weren't using c++ strings you were using c strings.

    C string = a null terminated array of characters
    C++ string = a class found in <string>

  8. #8
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Dang it! Oh well.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with calloc and pointers to strings.
    By sweetarg in forum C Programming
    Replies: 1
    Last Post: 10-24-2005, 02:28 PM
  2. remove strings from array
    By ipe in forum C Programming
    Replies: 2
    Last Post: 01-12-2003, 04:53 AM
  3. finding strings in strings
    By watshamacalit in forum C Programming
    Replies: 14
    Last Post: 01-11-2003, 01:08 AM
  4. damn strings
    By jmzl666 in forum C Programming
    Replies: 10
    Last Post: 06-24-2002, 02:09 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM