1) "hello " is a string literal. It is prohibited to change it.
2) Do not use casts. Most often cast == bad program style.
3) You need to make sure that destination has enough free space to append second c-string
The correct thing is make a local buffer large enough for your use, initialise it with "hello" and append the content while respecting the limited size of the buffer.
1 2 3 4 5 6 7
int main()
{
char s1[20] = "hello "; // create a buffer, 20 chars long, initialised with "hello "
constchar* s2 = "everyone!"; // s2 points to the string "everyone!" held in read-only memory somewhere
strncat(s1, s2, sizeof(s1)); // append s2 to s1, but don't overrun the buffer s1
}
Actually string is guaranteed to be null-terminated after call to strncat. I had to decrease leftover size by 1, or else terminating 0 will overflow on long strings.