Design a C program to remove the special symbols from the input string, and print the characters present in the string and the number of symbols. Symbols: * + << >>
Runtime Input :
XYZ**ABC++
Output :
XYZABC
6
#include <stdio.h>
int is_symbol(char ch) {
return ch == '*' || ch == '+' || ch == '<' || ch == '>' || ch == '\n';
}
int main() {
char str[1024];
char *p, *q;
int count=0;
fgets(str, 1024, stdin);
p = q = str;
while (*p) {
if (!is_symbol(*p)) {
count++;
*q = *p;
q++;
}
p++;
}
*q = '\0';
printf("%s\n", str);
printf("%d\n", count);
return 0;
}
Comments
Leave a comment