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

简单指针有关问题求教

2012-05-04 
简单指针问题求教下面这段指针程序在wintc中可以运行 在dev中就不可以了,不知道怎么修改?请教#includestd

简单指针问题求教
下面这段指针程序在wintc中可以运行 在dev中就不可以了,不知道怎么修改?请教
#include<stdio.h>
#include<string.h>
main()
{
char* p[3];
int i;
for(i=1; i<3; i++)
{
p[i]=" ";
}
strcpy(p[1], "nihao"); 
printf("%s",p[2]);
getch();
}

[解决办法]
#include<stdio.h>
#include<string.h>
main()
{
char* p[3];
int i;
for(i=1; i<3; i++)
{
p[i]=" ";
}
strcpy(p[1]=(char *)malloc(256), "nihao");
printf("%s",p[2]);
getch();
}
[解决办法]

探讨
为什么要给p1开辟空间而不给P2开辟呢

热点排行