GreenHand
V2EX  ›  问与答

这几行代码问题出在哪里?

  •  
  •   GreenHand · Jan 19, 2014 · 3523 views
    This topic created in 4677 days ago, the information mentioned may be changed or developed.
    很简单的C代码,执行时会报错:Abort trap: 6

    void strcat2(char *s, char *t) {
    //s指向'\0'
    while(*s)
    s++;
    while(*s++ = *t++)
    ;
    }

    int main() {
    char s[] = " hello ";
    char t[] = " world ";
    strcat2(s, t);
    printf("%s\n", s);
    printf("%s\n", t);
    }
    6 replies  •  1970-01-01 08:00:00 +08:00
    GreenHand
    GreenHand
    OP
    Jan 19, 2014
    1
    (⊙o⊙)…这缩进
    windywinter
    windywinter
    Jan 19, 2014❤️1
    2
    s空间不够呗
    nagato
    nagato
    Jan 19, 2014
    3
    到处都是问题 - -
    cassyfar
    cassyfar
    Jan 19, 2014
    4
    突然觉得喷神王ying的有篇文章还是多有道理的,代码的简洁不在于行数在于表意。
    GreenHand
    GreenHand
    OP
    Jan 19, 2014
    5
    @windywinter 多谢指正!
    @nagato ^_^
    @cassyfar 请说透了
    dialox
    dialox
    Jan 20, 2014
    6
    这个代码。。。。

    惨不忍睹~
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   507 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 21:44 · PVG 05:44 · LAX 13:44 · JFK 16:44
    ♥ Do have faith in what you're doing.