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

后端 未结 7 531
有刺的猬
有刺的猬 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..

    0 讨论(0)
提交回复
热议问题