I am new to C programming. One of my assignment questions is giving me a hard time. Here it is:
Write an ANSI-C program that uses getchar() to read characters from the standard input, and uses putchar() to output only the letters, spaces (' ') and newlines in the input to the standard output. If the letters are lower case letters, your program should convert them into upper cases. For example, given the following input:
There are 6 apples and 8 oranges, also 9 bananas ...... @ Apple Store!! See you there!?
the output of your program should be:
THERE ARE APPLES AND ORANGES ALSO BANANAS APPLE STORE SEE YOU THERE
I can get the capitalization part right but am having a hard time with ignoring numbers and any other character. Any help would be much appreciated.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int c;
while ((c=getchar())!=EOF) {
if ((c>='a' && c<='z'))
c -= 32;
else
while((c==getchar())<'a' || (c==getchar())>'z' ||(c==getchar())!='\n' ||(c==getchar())!=' '); //This is where I am having trouble.
putchar(c);
}
}