easy char qt
I haven't programmed in a LONG time, so bear with me...
in c++, I do:
char *str = "Hello";
sentence[0] = sentence[1];
cout << sentence[0] << endl;
Gives me an error (more like it crashes).
What's up with that?
sorry, it should have been:
char *str = "Hello";
str[0] = str[1];
// something along those lines...
// whenever I assign an individual character from
// str to another character, the program crashes
cout << str[0] << endl; // program crashes!
This seems like the most basic thing you could possibly do, yet it crashes! What's wrong with it?
char *str = "Hello";
str[0] = str[1];
// something along those lines...
// whenever I assign an individual character from
// str to another character, the program crashes
cout << str[0] << endl; // program crashes!
This seems like the most basic thing you could possibly do, yet it crashes! What's wrong with it?
You cannot change literal strings. You should copy the string first.
char str[] = "Hello";str[0] = str[1];cout << str[0] << endl;
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement