Thread: seperate varibale

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

    seperate varibale

    in a program i want the user to insert his name. then have each letter of his name turn into a variblae, like if his name is Eric....
    variableone would equal E
    variabletwo would equal R
    varibalethree would equal I
    vairbalefour would equal C

    get it? I have searhc around. I tried to search th cboards but it went to slow. i tried like 10 times
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    if you read something into a char pointer, you already have done that.

    x[0] = 'E';
    x[1] = 'r';
    x[2] = 'i';
    x[3] = 'c';

  3. #3
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > if you read something into a char pointer, you already have done that.
    Code:
    #include <iostream>
    using namespace std;
    
    int main ( void )
    {
        	char * autotext = "1 2 3 4 5 6 7 8 9 0";
    	char * ptrtext;
            for ( ptrtext = autotext; * ptrtext != '\0'; ptrtext++ )
            {
                    cout << * ptrtext << endl;
            }
            return 0;
    }
    In the above example, autotext has been initialized and filled already.
    However, if you were to fill it later on in your program, this would still work.

    autotext is an array of 20 characters.
    I'm printing each one on a new line, with a carriage return inbetween each one.

    You may manipulate the data as needed.
    The world is waiting. I must leave you now.

  4. #4
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Code:
    #include <string>
    #include <iostream>
    
    using namespace std;
    
    int main()
    { string name;
       int foo=0;
       int length;
       cin>>name;
       length=name.length()-1;
       while(foo<length)
       {   cout<<name[foo]<<endl;
            foo++;
       }
       return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 04-20-2009, 06:44 AM
  2. casting the system exstracted date into seperate ints
    By bazzano in forum C Programming
    Replies: 1
    Last Post: 08-30-2005, 12:17 AM
  3. How do I seperate integers?
    By Guti14 in forum C++ Programming
    Replies: 11
    Last Post: 12-22-2003, 01:24 PM
  4. opening seperate window to display bitmaps
    By Isometric in forum Windows Programming
    Replies: 24
    Last Post: 11-12-2003, 03:48 AM
  5. Seperate header files
    By Stan100 in forum C++ Programming
    Replies: 8
    Last Post: 04-01-2003, 03:48 PM