红联Linux门户
Linux帮助

错在哪里阿?

发布时间:2009-03-25 12:17:17来源:红联作者:ghostlpc
//Copy the string
#include
#include

int main(void)
{
char *apple = "Hello,world!";
char *pear;

while((*pear++ = *apple++) != '\0')
;

exit (0);
}

大家帮我看看阿 ,老是出错,是在没有搞明白
文章评论

共有 6 条评论

  1. 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;
    }

  2. bournewang 于 2009-03-25 16:10:56发表:

    是这个地方的原因char *pear;没有进行初始化就赋值是不行的。

  3. ghostlpc 于 2009-03-25 15:59:08发表:

    找到答案了,自己想了一节课,明白了 !

  4. ghostlpc 于 2009-03-25 13:26:33发表:

    我感觉这么没有错啊,但是提示段错误,给我看看啊

  5. zhaoyuzhong3694 于 2009-03-25 13:25:09发表:

    哥们的C语言还是初级,不懂,同情中……

  6. deepwhite 于 2009-03-25 12:59:37发表:

    谁写的?
    啥呀这是……