Possible Duplicate:
Why do I get a segmentation fault when writing to a string?
What is the difference between char a[] = “string”; and char *p = “string”;
Can anyone point out the problem in following program:
#include <stdio.h>
int main()
{
char *c = "Hello World!! !!";
char c2 = 'X';
while(c)
{
if(*c == ' ')
{
printf("%s",c);
*c = c2;
}
c++;
}
return 0;
}
It crashes at *c = c2;
with following error :
Thread [1] (Suspended : Signal : EXC_BAD_ACCESS:Could not access memory)
main() at mainclass.cpp:64 0x100000d74
I used GCC as compiler on MAC OSX and Eclipse as IDE.