// Using strchr
#include <stdio.h>
#include <string.h>
// ------------------------------------------------------------
// removeQuotesAndCommas
// Removes single quotes ('), double quotes ("), and commas (,)
// using strchr to check if a character is unwanted.
// ------------------------------------------------------------
void removeQuotesAndCommas(const char *input, char *output) {
const char *unwanted = "'\","; // characters to remove
int j = 0;
for (int i = 0; input[i] != '\0'; i++) {
if (strchr(unwanted, input[i]) == NULL) {
output[j++] = input[i]; // keep allowed characters
}
}
output[j] = '\0';
}
int main() {
const char s[] = "\"Imagine there's, no heaven\", 'Imagine' \"all\", the people.";
char cleaned[256];
removeQuotesAndCommas(s, cleaned);
printf("Original: %s\n", s);
printf("Cleaned: %s\n", cleaned);
return 0;
}
/*
run:
Original: "Imagine there's, no heaven", 'Imagine' "all", the people.
Cleaned: Imagine theres no heaven Imagine all the people.
*/