2012-11-25 58 views
1

好後,代碼不會繼續,而環

一切正常這裏,除了最後printf我打電話的。 我要輸出的字符刪除此代碼:

#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; 
} 

回答

5

的getchar()時,有沒有其他的可用輸入被阻塞和你不是從文件重定向標準輸入。它會一直等到你做更多的輸入,或者用CTRL + D(Linux)或CTRL + Z(Windows)發送EOF到終端。

1

Just Hit Enter不關閉輸入流(在這種情況下是標準輸入),所以你的程序一直運行(這是正確的)。當我按Ctrl + D(這發送EOF)時,我得到已刪除字符的數量,程序結束。