首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

指针和数组,该怎么解决

2012-04-06 
指针和数组char *ip malloc(strlen(192.168.0.1))char ip[] 192.168.0.1这俩个赋值有什么区别?

指针和数组
char *ip = malloc(strlen("192.168.0.1"));
char ip[] = "192.168.0.1";

这俩个赋值有什么区别?为什么传参时传malloc的就段错误,传数组就没问题呢?(例如strtok()函数)

[解决办法]
测试 char *s = (char *)malloc(strlen("Golden Global View")+1);
s = "Golden Global View";
s[3]='5';出错
因为"Golden Global View";是字符串常量,不能被修改。
[解决办法]
strtok函数内部可能修改了第一个参数的值,所以出错

热点排行