I have to "write a program that reads words from the keyboard to a char array. The program should then copy the text string in that char array to another char array". I'm not allowed to use strcpy.
const int max = 100;char myArray[max];string myString; getline(cin, myString);int size = myString.size(); for (int i = 0; i < size; i++) myArray = myString;
I'm not sure what code I should be using to copy the string to another array. In fact, I'm not entirely sure I'm doing this right, since my string is stored in a string object, and then I put each char in that string in a char array.
for (int i = 0; cin.get(c); i++) myArray = c;
Above code would be reading each char and store it directly in an array, but I don't know how to break this for-loop. If I wanted to break it once it reads a space character then I'd declare a variable char space = ' '; and then make something like: if (cin >> space) { break; } but that doesn't work either. Most likely because it reads one char at a time and pressing ENTER to execute the program would count as a space.
So, in short: How do I directly store what I type in in an array?
Thanks for any and all help!
[Edited by - Metallon on December 29, 2010 2:40:53 AM]