-
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
-
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';
-
> 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.
-
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;
}