In-Place String Reverse in C

后端 未结 3 1157
一生所求
一生所求 2021-01-27 16:45

I am trying to learn the fundamentals of C, but I cannot figure out why this code doesn\'t work. The while loop in reverse() causes a bus error. I found almost identical code

3条回答
  •  囚心锁ツ
    2021-01-27 17:39

    You are trying to change a string literal which leads to undefined behavior.

    Change

    char* a = "12";
    

    to

    char a[] = "12";
    

提交回复
热议问题