diff --git a/1 b/1 new file mode 100644 index 0000000..851b8ed --- /dev/null +++ b/1 @@ -0,0 +1,22 @@ + +e21 +d +d2d2 +2d +1 +2d +12d +1 +d1 +d +1 +d +d +d + +d ds +da +dsa +da +d ds +adsad diff --git a/2 b/2 new file mode 100644 index 0000000..c5fb842 --- /dev/null +++ b/2 @@ -0,0 +1,4 @@ +dsad dasdad dsadad +dasda da sda sdad asd asd +dasd da sda +dasda adsad diff --git a/3 b/3 new file mode 100644 index 0000000..66dd194 --- /dev/null +++ b/3 @@ -0,0 +1,8 @@ +wqxe +qxqw +xeq +xeqw +xq +xxqweeeeee +xqeqwx qeqxweq +xqewxqwex eqweqw diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c47f71d --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +OBJ = str.o str_test.o util.o + +CFLAGS = -Wall + +TARGET=myprog + +all: $(TARGET) + +$(TARGET): $(OBJ) + $(CC) $(CFLAGS) -o $@ $^ + +%.o: %.c + $(CC) -c $(CFLAGS) -o $@ $< + +clean: + rm $(TARGET) $(OBJ) diff --git a/myprog b/myprog new file mode 100755 index 0000000..89a528f Binary files /dev/null and b/myprog differ diff --git a/str.o b/str.o new file mode 100644 index 0000000..f5f12e1 Binary files /dev/null and b/str.o differ diff --git a/str_test.c b/str_test.c index 898a292..9df506a 100644 --- a/str_test.c +++ b/str_test.c @@ -114,4 +114,4 @@ main(int argc, char *argv[]) { test_it(); return 0; -} \ No newline at end of file +} diff --git a/str_test.o b/str_test.o new file mode 100644 index 0000000..4b7811a Binary files /dev/null and b/str_test.o differ diff --git a/util.o b/util.o new file mode 100644 index 0000000..346f2eb Binary files /dev/null and b/util.o differ diff --git a/wcl b/wcl new file mode 100755 index 0000000..4212e22 Binary files /dev/null and b/wcl differ diff --git a/wcl.c b/wcl.c new file mode 100644 index 0000000..45c6037 --- /dev/null +++ b/wcl.c @@ -0,0 +1,36 @@ +#include +#include +#include +void process_file(const char *filename, long *lines, long *words, long *bytes) { + FILE *file = fopen(filename, "r"); + if (!file) { + perror(filename); + return; + } + int ch; + int in_word = 0; + while ((ch = fgetc(file)) != EOF) { + (*bytes)++; + if (ch == '\n') (*lines)++; + if (isspace(ch)) { + in_word = 0; + } + else if (!in_word) { + in_word = 1; + (*words)++; + } + } + fclose(file); +} +int main(int argc, char *argv[]) { + long total_lines = 0, total_words = 0, total_bytes = 0; + printf("Name\tLines\tBytes\tWords\n"); + for (int i = 1; i < argc; i++) { + long lines = 0, words = 0, bytes = 0; + process_file(argv[i], &lines, &words, &bytes); + printf("%s\t%ld\t%ld\t%ld\n",argv[i], lines, bytes, words); + total_lines += lines; + total_words += words; + total_bytes += bytes; + } +}