I am wondering why am I getting segmentation fault in the below code.
int main(void)
{
char str[100]="My name is Vutukuri";
char *str_old,*str_new;
str_old=str;
strcpy(str_new,str_old);
puts(str_new);
return 0;
}
You haven’t initialized
*str_newso it is just copyingstr_oldto some random address.You need to do either this:
or
You will have to
#include <stdlib.h>if you haven’t already when using the malloc function.