Attempting to make an AI. Please read!

How would I write a program which, every time space was pressed, it would convert the string into a char array? This is my code so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
#include <fstream>
#include <cstring>
using namespace std;

int main()
{
    string first;
    char myword[1000];
    cout << "Hello there! What would you like?" << endl;
    getline (cin, first);
    strcpy(myword, first.c_str());
    return 0;
}



Also, if possible, is there a way to assign a letter to a number? For example 1 == a, 2 == b etc, just so that listing words would be easier? Or, if you guys could come up with a better solution, thank you! I did a lot of programming over the summer, stopped for a while and am only just getting back into the swing of things, so I should understand most of what your code will do.
If possible, could you explain what your code does, so that I learn what it does!

Thanks in advance, I know I'm asking a lot!
for(;;){
cin >> currentChar;
if (currentChar==' '){
charArray = someString.c_str();
}else{
someString.appnd(currentChar);
}
}

---

chars are numbers already
http://www.ascii.cl/htmlcodes.htm

cout<<(char)67;
will display
C
Last edited on
I get an error from the first code; it doesn't seem to work. I think I'll put thi project on hold so that I can improve with time.



cheked
1
2
3
4
5
6
7
8
9
10
11
12
13
char currentChar;
const char* charArray;
string someString;

for(;;){
	cin >> currentChar;
	if (currentChar=='1'){//space char cannot be read, '1' is used
		charArray = someString.c_str();
		//do something with charArray 
	}else{
		someString.push_back(currentChar);
	}
}
Last edited on
Topic archived. No new replies allowed.