How to remove all occurrences of a given character from string in C?

后端 未结 7 605
有刺的猬
有刺的猬 2020-11-30 11:24

I\'m attempting to remove a character from a string in C. The problem I am having with my code is that it removes the first instance of the character from the string but als

7条回答
  •  醉酒成梦
    2020-11-30 11:57

    just change

    if (*ptr1 == c) *ptr1 = 0;
    

    to

    if (*ptr1 == c) continue;
    

    as @ouah said, it breaks at the first NULL character..

提交回复
热议问题