wc/wc.c

24 lines
457 B
C
Raw Normal View History

#include <stdio.h>
2023-09-08 21:02:54 +00:00
#include <unistd.h> // read, isatty
2023-09-08 21:02:54 +00:00
// STDIN_FILENO
int process_fp(FILE* fp)
{
char buffer[1];
while (read(0, buffer, sizeof(buffer)) > 0) {
printf("%c", buffer[0]);
}
return 0;
}
int main(int argc, char** argv)
{
//
if (!isatty(STDIN_FILENO)) { // check if stdin is coming from terminal or pipeline
return process_fp(STDIN_FILENO);
} else if(argc > 1){
printf("To do");
}
return 0;
}