I'm trying to write a program that counts the blank spaces, letters and numbers in a user-input line.
A fox has 4 legs
Total blank spaces: 4
Total numbers: 1
Total Letters: 11
The book I'm reading has the following C code:
Now whenever I build and run, the program allows me to type anything infinitely.
void main(int argc, char **argv)
int ws = 0;
int dig = 0;
int al = 0;
while ((c = getchar()) !=EOF)
if (isdigit(c)) dig++;
else if (isalpha(c)) al++;
else if (isspace(c)) ws++;
printf("Blank Spaces: %d\n", ws);
printf("Digits: %d\n", dig);
printf("Alphabitical Chars: %d\n", al);
The problem is how do I stop from typing and make the program count the numbers, blank spaces and chars?.
Whenever I close it I get: Process terminated with status -1073741510
PS) The book is really, really crap and does not give further explanations, just the question and the answer, but I have no other choice to read other books.
I will be giving exams in 15 days it has around 20 questions in C programming language (total questions: 450) and I don't have the funkiest idea/clue of C.
To be honest, I do not have enough time to learn C programming language.
I'm really sorry for making topics for each program I'm trying to make.
The book is bad-written, it has lots of mistakes in the code