Compare commits
2 Commits
0289a812f5
...
2baca20487
Author | SHA1 | Date |
---|---|---|
Mid Favila | 2baca20487 | |
Mid Favila | c772d723ef |
|
@ -7,7 +7,7 @@ LDLIBS =
|
|||
PREFIX = /usr/local/bin/
|
||||
DESTDIR =
|
||||
|
||||
all: echo wc yes true false cat
|
||||
all: echo yes true false cat
|
||||
echo: echo.c
|
||||
wc: wc.c
|
||||
yes: yes.c
|
||||
|
@ -17,7 +17,7 @@ false:
|
|||
cat: cat.c
|
||||
|
||||
clean:
|
||||
rm echo true wc yes false cat
|
||||
rm echo true yes false cat
|
||||
|
||||
.SUFFIXES: .c .o
|
||||
.c.o:
|
||||
|
|
|
@ -100,7 +100,6 @@ int main(int argc, char **argv)
|
|||
buf = tmpbuf;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(!fppresence)
|
||||
|
|
13
src/common.h
13
src/common.h
|
@ -5,19 +5,6 @@
|
|||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
/* arrconcat -- function to copy copy_n bytes from arr2 to arr1, starting at startpos (in arr1) */
|
||||
void arrconcat(char* arr1, char* arr2, unsigned int startpos, unsigned int copy_n)
|
||||
{
|
||||
unsigned int i, i2;
|
||||
|
||||
|
||||
for(i = startpos, i2 = 0; i <= copy_n && arr2 != NULL; i++, i2++)
|
||||
{
|
||||
arr1[i] = arr2[i2];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* arrccat -- function to copy arr2len bytes from arr2 to the arr1len'th position of arr1. returns *newarr, and stores the length */
|
||||
/* of newarr[] in arr1len (that's why it needs to be a pointer to arr1len and not just a long unsigned integer). */
|
||||
char *arrccat(char *arr1, char *arr2, size_t *arr1len, size_t arr2len)
|
||||
|
|
67
src/wc.c
67
src/wc.c
|
@ -1,67 +0,0 @@
|
|||
#include "common.h"
|
||||
|
||||
enum {
|
||||
LINES,
|
||||
WORDS,
|
||||
BYTES
|
||||
};
|
||||
|
||||
int* count_values(FILE *fp)
|
||||
{
|
||||
static int count[3] = {0};
|
||||
char in_word, c;
|
||||
in_word = c = 0;
|
||||
|
||||
while((c = getc(fp)) != EOF)
|
||||
if(in_word)
|
||||
switch(c)
|
||||
{
|
||||
case '\n':
|
||||
count[LINES]++, count[BYTES]++;
|
||||
in_word = 0;
|
||||
break;
|
||||
|
||||
case ' ':
|
||||
in_word = 0;
|
||||
count[BYTES]++;
|
||||
break;
|
||||
|
||||
case '\t':
|
||||
in_word = 0;
|
||||
count[BYTES]++;
|
||||
break;
|
||||
|
||||
default:
|
||||
count[BYTES]++;
|
||||
break;
|
||||
}
|
||||
else
|
||||
switch(c)
|
||||
{
|
||||
case '\n':
|
||||
count[LINES]++, count[BYTES]++;
|
||||
break;
|
||||
|
||||
case ' ':
|
||||
count[BYTES]++;
|
||||
break;
|
||||
|
||||
case '\t':
|
||||
count[BYTES]++;
|
||||
break;
|
||||
|
||||
default:
|
||||
count[WORDS]++, count[BYTES]++;
|
||||
in_word = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
return 0;
|
||||
|
||||
err:
|
||||
}
|
Loading…
Reference in New Issue