1.4 1.4.1 I enter “COMMAND + D” in mac to stop input, however the whole program stoped.

Zhao Yimin

Active Member
C++ Student
I use CLion to do the project in my mac. When I enter “COMMAND + D” in mac to stop input, however the whole program stoped.
Here is my code.
int number_characters = 0;
int number_words = 1;
int number_newlines = 0;
int c;
while((c=getchar()) != EOF)
{
if((c >= 65 && c<= 90)||(c >= 97 && c <= 122))
number_characters++;
else if(c == 10)
number_newlines++;
else if(c == 32)
number_words++;
}

printf("%d\n",number_characters);
printf("%d\n",number_newlines);
printf("%d\n",number_words);
 
Last edited:

MXuan

New Member
C++ Student
I use CLion to do the project in my mac. When I enter “COMMAND + D” in mac to stop input, however the whole program stoped.
Here is my code.
int number_characters = 0;
int number_words = 1;
int number_newlines = 0;
int c;
while((c=getchar()) != EOF)
{
if((c >= 65 && c<= 90)||(c >= 97 && c <= 122))
number_characters++;
else if(c == 10)
number_newlines++;
else if(c == 32)
number_words++;
}

printf("%d\n",number_characters);
printf("%d\n",number_newlines);
printf("%d\n",number_words);
Hello, Yimin! I come across the same problems as you. Could you share me how to solve the problem? Thank you very much.
 
Top