zha2530 于 2009-03-25 20:32:28发表:
#include #include #include int main(void) { char *apple = "hello,linux!"; char *pear=NULL; char *a; static char *p; a=apple; p = pear = (char *)malloc(strlen(apple)); while(*apple) { *pear=*apple; apple++; pear++; } *pear='\0'; printf("apple = %s\n",a); printf("pear = %s\n",p); return 0; }
bournewang 于 2009-03-25 16:10:56发表:
是这个地方的原因char *pear;没有进行初始化就赋值是不行的。
ghostlpc 于 2009-03-25 15:59:08发表:
找到答案了,自己想了一节课,明白了 !
ghostlpc 于 2009-03-25 13:26:33发表:
我感觉这么没有错啊,但是提示段错误,给我看看啊
zhaoyuzhong3694 于 2009-03-25 13:25:09发表:
哥们的C语言还是初级,不懂,同情中……
deepwhite 于 2009-03-25 12:59:37发表:
谁写的? 啥呀这是……
zha2530 于 2009-03-25 20:32:28发表:
#include
#include
#include
int main(void)
{
char *apple = "hello,linux!";
char *pear=NULL;
char *a;
static char *p;
a=apple;
p = pear = (char *)malloc(strlen(apple));
while(*apple)
{
*pear=*apple;
apple++;
pear++;
}
*pear='\0';
printf("apple = %s\n",a);
printf("pear = %s\n",p);
return 0;
}
bournewang 于 2009-03-25 16:10:56发表:
是这个地方的原因char *pear;没有进行初始化就赋值是不行的。
ghostlpc 于 2009-03-25 15:59:08发表:
找到答案了,自己想了一节课,明白了 !
ghostlpc 于 2009-03-25 13:26:33发表:
我感觉这么没有错啊,但是提示段错误,给我看看啊
zhaoyuzhong3694 于 2009-03-25 13:25:09发表:
哥们的C语言还是初级,不懂,同情中……
deepwhite 于 2009-03-25 12:59:37发表:
谁写的?
啥呀这是……