1
0
mirror of https://github.com/krislamo/knrc.git synced 2024-09-19 21:00:35 +00:00

Compare commits

...

7 Commits

4 changed files with 53 additions and 1 deletions

12
04-file-copying.c Normal file
View File

@ -0,0 +1,12 @@
#include <stdio.h>
/* Exercise 1-6 and 1-7 */
int main()
{
int c;
printf("EOF = %d\n", EOF);
while (c = getchar() != EOF)
printf("c = %d\n", c);
}

10
05-char-counting.c Normal file
View File

@ -0,0 +1,10 @@
#include <stdio.h>
int main()
{
double nc;
for (nc = 0; getchar() != EOF; ++nc)
;
printf("%.0f\n", nc);
}

21
06-line-count.c Normal file
View File

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

View File

@ -1,4 +1,4 @@
all: hello mathvars c2f
all: hello mathvars c2f input count countlines
hello: 01-hello-world.c
gcc -o ./bin/01-helloworld 01-hello-world.c
@ -9,5 +9,14 @@ 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:
$(RM) ./bin/*-*