为了账号安全,请及时绑定邮箱和手机立即绑定

这个错在哪里?为什么运行时显示segmentation fault

这个错在哪里?为什么运行时显示segmentation fault

C
非你不可1 2017-03-06 20:04:50
#include<stdio.h> void main() { char *str={"asd ag hhhk mk32"}; char *s; for(;*str!='\0';str++) if(*str!=' ') { *s=*str; s++; } *s='\0'; puts(s); }
查看完整描述

1 回答

?
wldraa

TA贡献33条经验 获得超17个赞

把 char *s 改成 char *s = (char*)malloc(sizeof(char) * 100); (可能要引入 malloc.h)

你没有为 s 分配内存,所以操作 s 指向的内存的时候会报这个错误 

查看完整回答
1 反对 回复 2017-03-06
  • 1 回答
  • 0 关注
  • 1380 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信