diff options
| author | Zhineng Li <[email protected]> | 2026-01-10 16:37:39 +0800 |
|---|---|---|
| committer | Zhineng Li <[email protected]> | 2026-01-10 16:37:39 +0800 |
| commit | 49891f6bce29843f503b437c84d83cb787ecfa87 (patch) | |
| tree | 50bd44422a907b869a6d4839df436f37a35be36d /ch01/ex08-count.c | |
| download | c-knr-exercises-49891f6bce29843f503b437c84d83cb787ecfa87.tar.gz c-knr-exercises-49891f6bce29843f503b437c84d83cb787ecfa87.zip | |
first commit
Diffstat (limited to 'ch01/ex08-count.c')
| -rw-r--r-- | ch01/ex08-count.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/ch01/ex08-count.c b/ch01/ex08-count.c new file mode 100644 index 0000000..c5052e6 --- /dev/null +++ b/ch01/ex08-count.c @@ -0,0 +1,22 @@ +#include <stdio.h> + +/* count blanks, tabs, and newlines in input */ +int main() +{ + int c; + int ns, nt, nl; + + ns = 0; + nt = 0; + nl = 0; + + while ((c=getchar()) != EOF) { + if (c == ' ') + ++ns; + if (c == '\t') + ++nt; + if (c == '\n') + ++nl; + } + printf("%d %d %d\n", ns, nt, nl); +} |
