I currently have a shell script in C that takes a command of a file, two numbers, mth line and nth line, and supposedly should output whats in between those lines:
for example:
./output file1 2 6
would output file from line 2 to line 6
I have it implemented currently in a way of outputting the whole file, I have been trying to change it to output specifically between those lines
this is my code
#include <fcntl.h>
int main(int argc, char *argv[])
{
int file;
int size;
int l[1000];
int firstNum = atoi(argv[2]);
int secondNum = atoi(argv[3]);
file = open(argv[1], O_RDONLY);
if( file == -1)
{
printf("\n cannot open file \n");
}
while ((size=read(file,l,80)) > 0)
write(1,l,size);
}
I tried to change l
and size
to firstNum
and secondNum
, which are the numbers entered from the command line, but still did not work and outputted one single line.
What is a better way of doing so ?