Compare commits
4 commits
9c41981502
...
dd31852c69
Author | SHA1 | Date | |
---|---|---|---|
dd31852c69 | |||
4f3655bf1d | |||
ba1fde2c65 | |||
f4d9ebff4a |
10 changed files with 42 additions and 3 deletions
11
Makefile
11
Makefile
|
@ -1,9 +1,14 @@
|
||||||
|
CC := cc -g -Wall -Wextra -Werror -ansi
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
|
|
||||||
all: out out/sh
|
all: out out/sh out/wc
|
||||||
|
|
||||||
out:
|
out:
|
||||||
mkdir -p -- $@
|
mkdir -p -- $@
|
||||||
|
|
||||||
out/sh: $(wildcard src/*.c)
|
out/sh: $(wildcard src/sh/*.c)
|
||||||
cc -g -Wall -Wextra -Werror -ansi -o $@ $^
|
$(CC) -o $@ $^
|
||||||
|
|
||||||
|
out/wc: $(wildcard src/wc/*.c)
|
||||||
|
$(CC) -o $@ $^
|
||||||
|
|
4
README.txt
Normal file
4
README.txt
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
recreations
|
||||||
|
====
|
||||||
|
|
||||||
|
A repo where I drop all program recreations I can.
|
30
src/wc/main.c
Normal file
30
src/wc/main.c
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
FILE *file;
|
||||||
|
if (argc > 1 && strcmp(argv[1], "-")) {
|
||||||
|
file = fopen(argv[1], "rb");
|
||||||
|
if (file == NULL) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
file = stdin;
|
||||||
|
}
|
||||||
|
|
||||||
|
int current = fgetc(file);
|
||||||
|
unsigned int nb_lines = 0;
|
||||||
|
|
||||||
|
while (current != EOF) {
|
||||||
|
if (current == '\n') {
|
||||||
|
nb_lines++;
|
||||||
|
}
|
||||||
|
|
||||||
|
current = fgetc(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
printf("%d\n", nb_lines);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue