Thread: multiline variable

  1. #1
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608

    multiline variable

    yes i did searhc the posts and looked on the internet. but is there a c++ varible that can hold data that is more than one line?
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    What do you mean by data which is on more than one line?

    Do you mean a structure, like:

    TPoint p;
    p.x = 20;
    p.y = 20;

  3. #3
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    ok i am making a game.... i need this to be a varible

    cout << "&&&&&&&&&&&-MENU-&&&&&&&&&&&&&& *"<<endl;
    cout << "& & **"<<endl;
    cout << "& 1. Resume Game & ****"<<endl;
    cout << "& & **** *******"<<endl;
    cout << "& & * * *********"<<endl;
    cout << "& 2. Save Game & * * *************"<<endl;
    cout << "& & **** *****************"<<endl;
    cout << "& & ** ##############"<<endl;
    cout << "& 3. View Status & ** #### ## ####"<<endl;
    cout << "& & ** ##### ## #####"<<endl;
    cout << "& & ** ##### ## #####"<<endl;
    cout << "& 4. View Map & ** ################"<<endl;
    cout << "& & ** ##############"<<endl;
    cout << "& & ** ############"<<endl;
    cout << "& 5. Go to Main Screen & ** %%%%%%%%%%%%%%%%%%%"<<endl;
    cout << "& & ** %%%%%%%%%%%%%%%%%%%%%"<<endl;
    cout << "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ** %%%%%%%%%%%%%%%%%%%%%%%%"<<endl;
    and i have 4 other like it with different ascii arts next to the menu, btu it takes 17 lines, i need each menu make to be a varible
    ----
    edit
    ----
    the thing is kinda deformed, if u compile it it might come out irght its supposed to be a menu (just ext) next to a character.
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  4. #4
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    on ur structure

    TPoint p;
    p.x = 20;
    p.y = 20;

    could i do like

    p.a = first line of menu
    p.b = second line of menu

    and so fourth and the varible would be p?
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  5. #5
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Are you sure you don't want to make it a function?

  6. #6
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    uh i dont know about functions yet

    would my way work i just asked about
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  7. #7
    Registered User raimo's Avatar
    Join Date
    Jun 2002
    Posts
    107
    Data that is more than one line? All strings can be variables. And so can this:
    char something[34]="First line\nSecond line\nThird line";
    I am not using Dev-C++.
    #!/usr/bin/env python
    import sys;file=open(sys.argv[0]);print file.read();file.close()

  8. #8
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    oh those are functions, i know abotu that crap, i wasnt htinking

    char something[17]="First line\n, Second line\n, Third line";

    isnt it like that tho?
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  9. #9
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    > oh those are functions, i know abotu that crap, i wasnt htinking

    No, those are strings (well, char arrays, whatever)

    > isnt it like that tho?

    No - you don't enough space.

  10. #10
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    wel here was the resualt
    Code:
    char mage[17] ="&&&&&&&&&&&-MENU-&&&&&&&&&&&&&&                   *\n&                             &                    **\n&  1. Resume Game             &                     ****\n&                             &       ****          *******\n&                             &      *    *       *********\n&  2. Save Game               &      *    *     *************\n&                             &       ****     *****************\n&                             &        **        ##############\n&  3. View Status             &        **       ####   ##   ####\n&                             &        **      #####   ##   #####\n&                             &        **      #####   ##   #####\n&  4. View Map                &        **       ################\n&                             &        **        ##############\n&                             &        **         ############\n&  5. Go to Main Screen       &        **      %%%%%%%%%%%%%%%%%%%\n&                             &        **     %%%%%%%%%%%%%%%%%%%%%\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&        **   %%%%%%%%%%%%%%%%%%%%%%%%\n";
    i cant use the char varible or any other arible i could htink of or find, wut vairble type should i use

    note u gotta scroll to the right
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  11. #11
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Wow... no.

    First - your char array only has space for 17 characters - you have a few more than that.

    Second - use a function. Seriously - read about it. Learn about them - you can't write anything of decent length without functions.

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You can solve both the length problem (by letting the compiler count the chars for you), and the formatting problem like so
    Code:
    char mage[] = "&&&&&&&&&&&-MENU-&&&&&&&&&&&&&&                   *\n"
                  "&                             &                   *\n"
                  "&  1. Resume Game             &                ****\n"
                  "&                             &";

  13. #13
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    thanks salem
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  14. #14
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    what would ever be the point in counting characters fi the ocmpiler can count for you?
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  15. #15
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Because sometimes you can't initialize the char array when it's created, and user input is needed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about printing a variable???
    By Hoser83 in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2006, 01:57 PM
  2. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 12:07 PM
  3. static class variable vs. global variable
    By nadamson6 in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2005, 03:31 PM
  4. write Variable and open Variable and get Information
    By cyberbjorn in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2004, 01:30 AM
  5. Replies: 8
    Last Post: 04-22-2002, 10:02 PM