include<stdio.h>
int main()
{
//char b[10];
char *a="goodone";
//a=b;
scanf("%s",a);//this scanf fails and thow segmentation fault.
printf("%s",a);
}
Why is this not working? I tried a lot with this scanf but, when I reserve memory for my variable a*(by assigning a=b (commented)) it works fine. Otherwise it doesn't. I believe that char *a will allocate some memory for its string,("goodone")and return that memory location to its value. And printf working fine with this belief why scanf not? please save me from this....