Hello, this question arose when testing the answer to one of k&r's exercises.
The idea is to count blanks, tabs, and newlines before EOF is reached.
insert
Code:
#include <stdio.h>
main()
{
int c;
int b = 0;
int t = 0;
int n = 0;
while ((c = getchar()) != EOF) {
if (c == ' ')
b++;
if (c == '\t')
t++;
if (c == '\n')
n++;
}
printf("Blanks : %d\nTabs : %d\nNewlines : %d\n", b, t, n);
}
Starting the program then pressing CTRL-C yields :
C:\>counter.exe
Blanks : 0
^C
C:\>
So the process, after it gets the SIGINT signal, breaks it out of the loop and prints part of the printf statement. Why only part . . . wondering if anyone knows what is going on inside the computer, thanks.