Using getchar and putchars

Joined
Jan 24, 2022
Messages
7
Reaction score
0
hi,

i am trying to write a code where it reads characters from its input and writes the same characters to its output, except it does not write lower case vowels ('a', 'e', 'i', 'o', 'u').

I have to use getchar() to read input.
Can anyone tell me what i am missing from this code?

#include <stdio.h>
int main(void) {
int character = getchar();
while (character != EOF) {
if (character != 'a' || 'e' || 'i' || 'o' || 'u') {
putchar(character);
}
character = getchar();
}
return 0;
}
 
Joined
Nov 13, 2020
Messages
302
Reaction score
38
It's been forever since I programmed in C so just try this and hope for it to work
if (character !('a' || 'e' || 'i' || 'o' || 'u')){...}
 
Joined
Mar 3, 2021
Messages
240
Reaction score
30
You'll have to write it all out individually. You can maybe make a cleaner version with a switch statement instead of if.

C:
if (character != 'a' && character != 'e' && character != 'i' && character != 'o' && character != 'u'){
    putchar(character);
}

That's when it pays to make shorter variable names.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top