mirror of https://git.qorg11.net/k9core.git
Improved wc
This commit is contained in:
parent
971e32a781
commit
9d6db6fc47
27
src/wc.c
27
src/wc.c
|
@ -1,12 +1,12 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int
|
void
|
||||||
main(void)
|
wc(FILE *file)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
int newlines = 0, spaces = 0, bytes = 0;
|
int newlines, spaces, bytes = 0;
|
||||||
|
newlines = spaces = bytes = 0;
|
||||||
while((c = getchar()) != EOF)
|
while((c = fgetc(file)) > 0)
|
||||||
{
|
{
|
||||||
bytes++;
|
bytes++;
|
||||||
if(c == '\n')
|
if(c == '\n')
|
||||||
|
@ -14,7 +14,22 @@ main(void)
|
||||||
if(c == ' ')
|
if(c == ' ')
|
||||||
spaces++;
|
spaces++;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%i %i %i\n",newlines,spaces,bytes);
|
printf("%i %i %i\n",newlines,spaces,bytes);
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
if (argc == 1)
|
||||||
|
wc(stdin);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(int i = 1; i<argc;i++)
|
||||||
|
{
|
||||||
|
wc(fopen(argv[i],"r"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue