Using getchar and putchars


Joined
Jan 24, 2022
Messages
3
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;
}
 
Ad

Advertisements

Joined
Nov 13, 2020
Messages
125
Reaction score
20
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')){...}
 
Ad

Advertisements

Joined
Mar 3, 2021
Messages
243
Reaction score
29
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

Top