hi, this code will compile but when i run it it crash on me..I have found the prolem but i can't seem to fix it. its on strcpy that i'm getting the problem.. How do i fix it so that it will stop crashing. I get a return value of 255 when it crashes
int main(int argc, char** argv) {
string wordoftheday;
vector<string> first_word_of_the_day;
srand(time(NULL));
int random = rand() % ( 30);
ifstream word_of_the_day("word_of_the_day.txt");
while (getline(word_of_the_day, wordoftheday))
{
first_word_of_the_day.push_back(wordoftheday);
}
char wordotd[100];
strcpy (wordotd,first_word_of_the_day[random].c_str()); //the prolem is right here, program crash on this line
cout <<wordotd<<endl;
return 0;
}
strcpy relies on you making sure that the target memory is correct, the source memory is correct, and that you don't write so much that you overrun the target memory.