1
0
mirror of https://github.com/krislamo/knrc.git synced 2024-11-14 02:00:35 +00:00

Compare commits

..

No commits in common. "0c2d0fae2bf8a897f22a77585ec5425358b27b22" and "93acdbe7e9a87c196bdc6282ad6751daccc75707" have entirely different histories.

5 changed files with 18 additions and 129 deletions

View File

@ -1,16 +0,0 @@
#include <stdio.h>
int main()
{
int c;
int l;
while ((c = getchar()) != EOF) {
if (c == ' ' && c == l) {
;
} else {
printf("%c", c);
l = c;
}
}
}

View File

@ -1,17 +0,0 @@
#include <stdio.h>
int main()
{
int c;
while ((c = getchar()) != EOF) {
if (c == '\t')
printf("\\t");
else if (c == '\b')
printf("\\b");
else if (c == '\\')
printf("\\\\");
else
printf("%c", c);
}
}

View File

@ -1,25 +0,0 @@
#include <stdio.h>
#define IN 1
#define OUT 0
/* count lines, words, and characters in input */
int main()
{
int c, nl, nw, nc, state;
state = OUT;
nl = nw = nc = 0;
while ((c = getchar()) != EOF) {
++nc;
if (c == '\n')
++nl;
if (c == ' ' || c == '\n' || c == '\t')
state = OUT;
else if (state == OUT) {
state = IN;
++nw;
}
}
printf("%d %d %d\n", nl, nw, nc);
}

View File

@ -1,10 +1,22 @@
CC = gcc all: hello mathvars c2f input count countlines
OBJS = $(patsubst %.c,bin/%,$(wildcard *.c))
all: $(OBJS) hello: 01-hello-world.c
gcc -o ./bin/01-helloworld 01-hello-world.c
$(OBJS): mathvars: 02-vars-and-math.c
$(CC) -o ./$@ $(patsubst bin/%,%.c,$@) gcc -o ./bin/02-mathvars 02-vars-and-math.c
c2f: 03-celsius-to-fahrenheit.c
gcc -o ./bin/03-c2f 03-celsius-to-fahrenheit.c
input: 04-file-copying.c
gcc -o ./bin/04-input 04-file-copying.c
count: 05-char-counting.c
gcc -o ./bin/05-count 05-char-counting.c
countlines: 06-line-count.c
gcc -o ./bin/06-line-count 06-line-count.c
clean: clean:
$(RM) ./bin/* $(RM) ./bin/*-*

View File

@ -152,68 +152,3 @@ https://github.com/krislamo/knrc/commit/588969b09fabab1e91ff4f4b1c37e87fc23cf76b
https://github.com/krislamo/knrc/blob/588969b09fabab1e91ff4f4b1c37e87fc23cf76b/02-vars-and-math.c[(Source)] https://github.com/krislamo/knrc/blob/588969b09fabab1e91ff4f4b1c37e87fc23cf76b/02-vars-and-math.c[(Source)]
Move some numbers around to reverse the table. Move some numbers around to reverse the table.
09-word-count.c
~~~~~~~~~~~~~~~~
https://github.com/krislamo/knrc/commit/d064db2b171e3da74fd5082ae29456f64caeafeb[(Diff)]
https://github.com/krislamo/knrc/blob/d064db2b171e3da74fd5082ae29456f64caeafeb/09-word-count.c[(Source)]
Textbook example of counting lines, words, and characters from input.
Exercise 1-11: test the word count program
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
No input:
----
$ ./bin/09-word-count
0 0 0
$
----
Just 3 newlines:
----
$ ./bin/09-word-count
3 0 3
$
----
Just 3 tabs:
----
$ ./bin/09-word-count
0 0 3
$
----
Just 3 spaces:
----
$ ./bin/09-word-count
0 0 3
$
----
Just a single word per line:
----
$ ./bin/09-word-count
one
word
per
line
4 4 18
$
----
Three blanks before and after:
----
$ ./bin/09-word-count
three blanks before/after 0 3 31
$
----