Remove identical, consecutive lines in a char array in C

前端 未结 1 1788
旧时难觅i
旧时难觅i 2021-01-29 09:29

I\'m trying to create a function that will detect if there are consecutive lines in a char array that are identical.

For example, if a char array contained:

1条回答
  •  说谎
    说谎 (楼主)
    2021-01-29 09:57

    Some guidance:

    • You only ever to copy each character at most once - backwards, to its destination. No need for extra copies.
    • You'll have a "finalized up to here" position in the array and a "being processed/read" position.
    • Keep track of the current full-line which may be duplicated, and match each new line against it to check whether it's a dupe.
    • Advance by full lines rather than by characters - except when looking for the next end-of-line.

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