k9core

Unnamed repository
Log | Files | Refs | LICENSE

commit 642d6f396c0e196702fa88949597e783350bf58d
parent 61a4887fb1124906d732c999461727505dd7a04a
Author: qorg11 <qorg@vxempire.xyz>
Date:   Wed,  5 Aug 2020 12:28:59 +0200

added head

Diffstat:
Asrc/head.c | 37+++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+), 0 deletions(-)

diff --git a/src/head.c b/src/head.c @@ -0,0 +1,37 @@ +#include <stdio.h> +#include <stdlib.h> + +int +head(FILE *file, int lines) +{ + int a; + int c = 0; + while((a = fgetc(file)) != EOF) + { + if(a == '\n') + { + ++c; + } + putchar(a); + if(c == lines) + return lines; + } + return lines; + +} + +int +main(int argc, char *argv[]) +{ + int lines = 10; + if(argc == 1) + head(stdin,lines); + if(argc == 2) + head(fopen(argv[1],"r"),lines); + if(argc == 3) + { + lines = abs(atoi(argv[1])); + head(fopen(argv[2],"r"),lines); + } + return 0; +}