#include <stdio.h> int main(void); int main(void){ char* string="hello"; char* p; for(p=string; *p!='\0' ;p++){ printf("p=%p : %c\n",p ,*p); if(*p=='l'){ *p = 'L';//ここで強制終了してしまう } getchar(); } return(0); }配列にするとうまくいくのですが、なぜなのでしょう?
#include <stdio.h> int main(void); int main(void){ char string[/url]="hello"; //char* string="hello"; char* p; for(p=string; *p!='\0' ;p++){ printf("p=%p : %c\n",p ,*p); if(*p=='l'){ *p = 'L'; } getchar(); } return(0); }ご指導いただけると幸いです。
ちなみに環境はVineLinux gccです。