mirror of https://git.qorg11.net/k9core.git
added head
This commit is contained in:
parent
61a4887fb1
commit
642d6f396c
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue