Answer to Question #301860 in C for Suvedhaa

Question #301860

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

1
Expert's answer
2022-02-23T16:18:11-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS