somebody pls fix flags and stdin

This commit is contained in:
qorg11 2020-07-30 13:59:34 +02:00
parent 3a44055d37
commit dcf829ab3e
No known key found for this signature in database
GPG Key ID: 343FC20A4ACA62B9
1 changed files with 28 additions and 25 deletions

View File

@ -45,41 +45,44 @@ main(int argc, char *argv[])
{
int c;
int show_lines, show_words, show_bytes;
show_lines = show_words = show_bytes = 0;
struct wc_values data;
/* Process arguments */
while((c = getopt(argc,argv,"lwc")) > 0)
{
switch(c)
{
case 'l':
show_lines = 1;
break;
case 'w':
show_words = 1;
break;
case 'c':
show_bytes = 1;
break;
default:
show_lines = show_words = show_bytes = 1;
}
{
case 'l':
show_lines = 1;
break;
case 'w':
show_words = 1;
break;
case 'c':
show_bytes = 1;
break;
}
}
for(int i = optind; i<argc;i++)
{
if(argc > 1)
{
data = wc(fopen(argv[i],"r"));
if(show_lines)
printf("%i ",data.lines);
if(show_words)
printf("%i ",data.words);
if(show_bytes)
printf("%i",data.words);
}
{
if(argc > i)
data = wc(fopen(argv[i],"r"));
else
data = wc(stdin);
/* printf("%i %i %i\n",show_lines, show_bytes,
show_words); */
if(show_lines)
printf("%i ",data.lines);
if(show_words)
printf("%i ",data.words);
if(show_bytes)
printf("%i",data.bytes);
}
printf("\n");
}
printf("\n");
return 0;
}