#include <stdio.h>
#include <string.h>
#define SIZE 5
void TrimPunctuation(char *s, char trimmed[]) {
char charsToTrim[] = "*!,._";
int start = 0;
int end = strlen(s) - 1;
while (start <= end && strchr(charsToTrim, s[start]) != NULL) {
start++;
}
while (end >= start && strchr(charsToTrim, s[end]) != NULL) {
end--;
}
strncpy(trimmed, s + start, end - start + 1);
trimmed[end - start + 1] = '\0'; // Null-terminate the string
}
int main() {
char *array[SIZE] = {
"C-Sharp!!!",
"...c",
"java,,,",
"c++",
"**python__"
};
char trimmed[128] = "";
for (int i = 0; i < SIZE; i++) {
TrimPunctuation(array[i], trimmed);
puts(trimmed);
}
return 0;
}
/*
run:
C-Sharp
c
java
c++
python
*/