My code is like this
Char * q = "Bye";
strcpy (&q[1], "K");
When I compile it, it starts hanging. I am using in MinGW in Windows 7.
Even if I allocate malloc
to q
, the problem persists
If i try to assign q[1]= 'K'
, then also it hangs
My code is like this
Char * q = "Bye";
strcpy (&q[1], "K");
When I compile it, it starts hanging. I am using in MinGW in Windows 7.
Even if I allocate malloc
to q
, the problem persists
If i try to assign q[1]= 'K'
, then also it hangs
When you initialize a char pointer with a string literal the compiler may store the string in read-only memory. If you really want to have the string be modifiable then try storing it on the local stack:
Char q[]="Bye";