|
-
October 2nd, 2009, 01:02 PM
#1
Need help with converting string to char array!
Hey everybody.
I am really having some big problems right now, this is totally blocking the program i am making right now, because i don't know how to do it.
Anyways, i wrote an example code with comments so you can see exactly what i mean:
Code:
int main(){
string string1;
cout << "Please enter your string:" << endl;
cin >> string1;
char char1[x];
// I need some way to make x the same size as string1's length. How would i do this?
// For example, if i entered "hello world" as a string, that is 11 characters. It would now have to
// initialize: char char1[11].. So how would i do this?
// Now i need something that converts the string1 to char1[x].. How would i do this?
// For example, if i entered "hello world" then it would make:
// char1[0] = h
// char1[1] = e
// char1[2] = l
// and so on, until it is done. How would i do this? I really need help :)
cout << char1;
// the cout should now be the same as you entered in cin..
}
Now, i was wondering if someone could fix my code so it works, or help me on how to do it?
Of course many of you wouldn't want to do everything for me, but i really like to just look at a good source code and learn how things work that way.
Anyways, some help would be awesome! And if someone will help me fix my code it would be perfect.
~Maxyz.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|