Question: Write a program in C... Your programs should only use system calls for obtaining input and generating output. For example, use read() and write() system

Write a program in C...

Your programs 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.

Write a program that accepts the name of a file from a command line. For example "./program textfile". It will then open a filename with that name in the local directory and enable the user to type in a line number and hit enter to view that line of text from the opened file. Remember to use read using the STDIN. After reading the file into a buffer, the program should repeatedly prompt the user for a line number and then display the appropriate line of text. This would continue until the read call indicates theres no more user data (interactively, youd press control-D).

You can assume that the file has less than 100 lines and that the total number of characters in the file is less than 8192 (create a static 8k buffer rather than dynamically allocating space).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!