c89
gcc (GCC) 4.6.3
Hello,
I am getting a stack dump on *search = ‘\0’; I thought it was possible to nul terminate a string.
char *ptr_name = "hello@home";
char *search = ptr_name;
search = strchr(ptr_name, '@');
search++;
*search = '\0';
Many thanks for any suggestions,
char *ptr_name = "hello@home";creates a string constant and that cannot be modified.To get the result that you are expecting, you need to allocate memory for
"hello@home"using an arraychar arr_name[] = "hello@home";– or dynamically usingmallocduring runtime.Your program should be as follows:
Output: