1

Well,

everything works well here, except of the last printf I call. I want to output the deleted characters in this code:

#include <stdio.h>

int del_lower_vowels(char c) {
    if(c=='a') {
        return 0;
    }
    if(c=='e') {
        return 0;
    }
    if(c=='i') {
        return 0;
    }
    if(c=='o') {
        return 0;
    }
    if(c=='u') {
        return 0;
    }
    else
        return c;
}

int main (void) {
    printf("Enter a string\n");
    int c;
    int del = 0;
    while((c=getchar()) != EOF)
    {
        c = del_lower_vowels(c);
        if(c==0)
        {
            del +=1;
        }
        putchar(c);
    }
    printf("Deleted characters: %d",del);
    return 0;
}
0

2 Answers 2

5

getchar() is blocking when there's no more input available and you're not redirecting stdin from a file. It will simply wait forever until you either do more input, or send an EOF to the terminal with CTRL+D (Linux) or CTRL+Z (Windows).

Sign up to request clarification or add additional context in comments.

Comments

1

Just hitting Enter does not close the input stream (standard input in this case), so your program keeps running (which is correct). When I hit Ctrl+D (this sends EOF), I get the number of deleted characters and the program ends.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.