forked from 131/lab0.1_letscontinue
11
This commit is contained in:
22
1
Normal file
22
1
Normal 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
4
2
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
dsad dasdad dsadad
|
||||||
|
dasda da sda sdad asd asd
|
||||||
|
dasd da sda
|
||||||
|
dasda adsad
|
||||||
8
3
Normal file
8
3
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
wqxe
|
||||||
|
qxqw
|
||||||
|
xeq
|
||||||
|
xeqw
|
||||||
|
xq
|
||||||
|
xxqweeeeee
|
||||||
|
xqeqwx qeqxweq
|
||||||
|
xqewxqwex eqweqw
|
||||||
16
Makefile
Normal file
16
Makefile
Normal 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)
|
||||||
@@ -114,4 +114,4 @@ main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
test_it();
|
test_it();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
str_test.o
Normal file
BIN
str_test.o
Normal file
Binary file not shown.
36
wcl.c
Normal file
36
wcl.c
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user