Try this:
while ((ch = getchar()) != '\n') {
if (isdigit(ch) {
printf("%c", ch);
}
}
Your code had one serious problem: you were not calling getchar()
inside the while
loop. So it would just read one character and repeatedly process that same character. The other problem was your if
condition -- the tests for ch != '*' || ch != '@'
would be true for all the alphabetic and space characters. If you only want to print digits, there's no need for those tests.
As I mentioned in the comment, this will process what the user types, not what you print with printf()
.