Why this below code gives segmentation fault?
int main()
{
char *t = "Working on RedHat Linux";
char *s;
s = malloc (8000 * sizeof(char));
memcpy(s,t,7000);
printf("s = %s\nt = %s\n",s,t);
free(s);
}
I have allocated 8000bytes for 's'. And copying only 't' to s untill 7000bytes. Though I have allocated 8000 bytes for 's', why its giving segmentation fault?
strcpyorstrncpyfor string copying.