I want to have a user input a string, read the length, and then put it into an array if it isn't already. I've been trying variations of cin.getline.. pointers and such, I never got anywhere. So can someone point me in the right direction?
What I want to try to do is reverse the string.. I got a pretty good idea how to do this, so I don't want any help on it right now. Thanks in advance, Dual.
This will work with char* only:
cin >> var; // what ever it is.
x = strlen(var);
cout << x;
this will display the # of letters (single word only):o
By the way, look at the tutorial next time before you come here
I think you meant to allocate more the one char on var.
He has a legitimate guestion. If you don't like the question don't answer it, but don't tell him to read the tutorial.
if you wish to allow the user to input a string containing whitespaces like "what's up Doc?", then you need to use getline:
char * input;
cout << "enter a string up to 79 char long. It may include whitespaces. Use ~ to terminate input. " << endl;
cin.getline(input, 80, '~');
cin.ignore(256, ''\n');//attempt to mop up anything entered after the tilde.
if you have to reverse the c_style string for an assignment by writing your own function, so be it. Otherwise, you can look up strrev() in your compiler's help section to save you a little hassle.