Answered step by step
Verified Expert Solution
Question
1 Approved Answer
IN C , Write a utility program that takes one or two arguments (filename and -n) and writes to STDOUT the first n lines of
IN C,
Write a utility program that takes one or two arguments (filename and -n) and writes to STDOUT the first n lines of the file filename. If filename is not specified, the program should read from STDIN If -n is not specified, the program should write only the first line. Your program should read the file 10 characters at a time.
Your should only use system calls for obtaining input and generating output. For example, use read() and write() system calls instead of C library functions (e.g. scanf or printf) to fetch input and display output.
1 abc 2 def ghi 3 jkl mno 4 par stu vwx 5 yz -/Documents/test> ./header abc abc def ghi jkl mno par stu vwx yz ABC DEF GHI JKL MNO POR STU VWX YZ -/Documents/test> ./header abc - 10 abc def ghi jklmno par stu vwx yz ABC | DEF GHI JKL MNO POR STU VWX 6 ABC 7 DEF GHI 8 JKL MNO 9 PQR STU VWX 10 YZ 11 12 123 456 6790 13 For initial testing, I set the default number of lines to print to 10. In the final version, the number should be 1. YZ - Documents/test> --/Documents/test> ./header abc - 1 abc - Documents/test> ./header abc -2 abc def ghi - Documents/test> ./header abc - 3 abc def ghi jkl mno - Documents/test> ./header abc - 5 abc def ghi jkl mno par stu vwx yz -/Documents/test> ./header abc -11 abc def ghi jkl mno par stu vwx yz ABC DEF GHI JKL MNO POR STU VWX YZ - Documents/test>Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started