In-Place String Reverse in C

后端 未结 3 1202
一生所求
一生所求 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:25

    The problem is that you're trying to reverse a constant literal string, which is read only. Change the declaration of a in main to char a[] = "12"; to make it a writable char array instead

提交回复
热议问题