19 main(
int argc,
char *argv[])
25 memset(prevkey, 0,
sizeof(prevkey));
26 while (fgets(line,
sizeof(line), stdin) != NULL) {
28 int len = (int)strlen(line);
32 if (cp[len-1] ==
'\n') {
36 cp = strchr(line,
' ');
45 while (cp - line < len) {
48 val = strtol(cp, &endptr, 10);
49 if (val == 0 && cp == endptr) {
57 if (strlen(prevkey) == 0) {
59 memset(prevkey,
sizeof(prevkey), 0);
61 strncpy(prevkey, key,
sizeof(prevkey)-1);
65 if (strcmp(prevkey, key) != 0) {
67 printf(
"%s %ld\n", prevkey, sum);
68 memset(prevkey,
sizeof(prevkey), 0);
70 strncpy(prevkey, key,
sizeof(prevkey)-1);
77 if (strlen(prevkey) > 0) {
78 printf(
"%s %ld\n", prevkey, sum);
#define KEYLEN
Maximum key-value string length.
int main(int argc, char *argv[])
Reducer main routine.
#define LINELEN
Maximum line length.