-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmywc.c
More file actions
57 lines (45 loc) · 1.5 KB
/
Copy pathmywc.c
File metadata and controls
57 lines (45 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*--------------------------------------------------------------------*/
/* mywc.c */
/* Author: Bob Dondero */
/*--------------------------------------------------------------------*/
#include <stdio.h>
#include <ctype.h>
/*--------------------------------------------------------------------*/
/* In lieu of a boolean data type. */
enum {FALSE, TRUE};
/*--------------------------------------------------------------------*/
static long lLineCount = 0; /* Bad style. */
static long lWordCount = 0; /* Bad style. */
static long lCharCount = 0; /* Bad style. */
static int iChar; /* Bad style. */
static int iInWord = FALSE; /* Bad style. */
/*--------------------------------------------------------------------*/
/* Write to stdout counts of how many lines, words, and characters
are in stdin. A word is a sequence of non-whitespace characters.
Whitespace is defined by the isspace() function. Return 0. */
int main(void)
{
while ((iChar = getchar()) != EOF)
{
lCharCount++;
if (isspace(iChar))
{
if (iInWord)
{
lWordCount++;
iInWord = FALSE;
}
}
else
{
if (! iInWord)
iInWord = TRUE;
}
if (iChar == '\n')
lLineCount++;
}
if (iInWord)
lWordCount++;
printf("%7ld %7ld %7ld\n", lLineCount, lWordCount, lCharCount);
return 0;
}