2020-06-16 16:52:17 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2020-06-16 19:28:56 +00:00
|
|
|
void
|
|
|
|
wc(FILE *file)
|
2020-06-16 16:52:17 +00:00
|
|
|
{
|
|
|
|
char c;
|
2020-06-16 19:28:56 +00:00
|
|
|
int newlines, spaces, bytes = 0;
|
|
|
|
newlines = spaces = bytes = 0;
|
|
|
|
while((c = fgetc(file)) > 0)
|
2020-06-16 16:52:17 +00:00
|
|
|
{
|
|
|
|
bytes++;
|
|
|
|
if(c == '\n')
|
|
|
|
newlines++;
|
|
|
|
if(c == ' ')
|
|
|
|
spaces++;
|
|
|
|
}
|
|
|
|
printf("%i %i %i\n",newlines,spaces,bytes);
|
2020-06-16 19:28:56 +00:00
|
|
|
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"));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-06-16 16:52:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|