K&R C Exercise 2-4: squeeze — Delete Characters from a String

Exercise 2-4. Write an alternative version of squeeze(s1,s2) that deletes each character in s1 that matches any character in the string s2. Approach The original K&R squeeze(s, c) removes all occurrences of a single character c from string s using a compact two-index pattern: index i scans every position in s, while index j only …

C program to delete n Characters from a given position in a given string.

Deleting n characters from a given position in a string is a common string manipulation task used in text editors, parsers, and data cleaning. The approach: shift all characters after the deleted region one step to the left, overwriting the deleted characters, then terminate the string with a null byte. The original post used gets() …