Compare commits

..

4 commits

Author SHA1 Message Date
dd31852c69 feat: add wc 2024-11-14 14:20:31 +01:00
4f3655bf1d feat: add wc 2024-11-14 13:39:17 +01:00
ba1fde2c65 refactor: move sh files in subfolder 2024-11-14 13:38:51 +01:00
f4d9ebff4a doc: add README 2024-11-14 13:32:45 +01:00
10 changed files with 42 additions and 3 deletions

View file

@ -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
View file

@ -0,0 +1,4 @@
recreations
====
A repo where I drop all program recreations I can.

30
src/wc/main.c Normal file
View 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;
}