yeah, looks to me like you're confusing chars with strings... you can use your code with just a few modifications:
Code:
#include <iostream>
//this is the function prototype
void someFunction(char*word);
int main()
{
//here we assume a phrase no bigger than 512 characters
char*word=new char[512];
//I designed the someFunction function so that we don't need strcpy
someFunction(word);
//output the response
std::cout<<word<<std::endl;
//deallocate that space
delete[]word;
//END.
return 0;
}
//function definition
void someFunction(char*word)
{
//prompt for input
std::cout<<"Hello World\n> "<<std::flush;
//get their input, up to 20 chars and stopping when they hit "ENTER"
std::cin.getline(word,20,'\n');
//assign the response to the parameter
strcpy(word,"Thank you for helping me test my AI");
//bye.
return;
}
here's an implementation using stl strings (this may be easier to use):
Code:
#include <iostream>
#include <string>
//this is the function prototype - notice the new ampersand (&)
void someFunction(std::string&word);
int main()
{
//stl strings take care of most of your size woes
std::string word;
//I designed the someFunction function so that we don't need strcpy
someFunction(word);
//output the response
std::cout<<word<<std::endl;
//notice we dont' need to deallcoate anything
//END.
return 0;
}
//function definition - The ampersand (&) means we're passing in the address
//of the variable.
void someFunction(std::string&word)
{
//prompt for input
std::cout<<"Hello World\n> "<<std::flush;
//Notice the changes in this next line - it still stops at ENTER, but
//there are no size limitations (theoretically)
getline(std::cin,word,'\n');
//an easier assignment is now possible thanks to the string class
word="Thank you for helping me test my AI";
//bye.
return;
}