You need to allocate space for it. Without any space, it is going outside what it automatically allocated
Code:
char str1[32] = "hello"; /* will allocate 32 but only use 6 */
/* Concatenate the string - works like += */
strcat (str1, "World");
printf ("%s\n", str1);
Not to mention the fact that str1 is pointing to a constant literal string, so even if you try to change it like this:
Code:
strcpy( str1, "HELLO" );
it should still blow up, since it's trying to change a constant. This may work fine on some platforms that don't enforce constant data very strictly, but it's definitely wrong and won't work on all platforms.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.