This commit is contained in:
etrushko05
2025-10-18 04:23:04 -04:00
parent b16b98d7b7
commit e5870253c4
11 changed files with 87 additions and 1 deletions

22
1 Normal file
View File

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

4
2 Normal file
View File

@@ -0,0 +1,4 @@
dsad dasdad dsadad
dasda da sda sdad asd asd
dasd da sda
dasda adsad

8
3 Normal file
View File

@@ -0,0 +1,8 @@
wqxe
qxqw
xeq
xeqw
xq
xxqweeeeee
xqeqwx qeqxweq
xqewxqwex eqweqw

16
Makefile Normal file
View File

@@ -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)

BIN
myprog Executable file

Binary file not shown.

BIN
str.o Normal file

Binary file not shown.

View File

@@ -114,4 +114,4 @@ main(int argc, char *argv[])
{
test_it();
return 0;
}
}

BIN
str_test.o Normal file

Binary file not shown.

BIN
util.o Normal file

Binary file not shown.

BIN
wcl Executable file

Binary file not shown.

36
wcl.c Normal file
View File

@@ -0,0 +1,36 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
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;
}
}