Chapter IIT Exercise 00 display file Exercice: 00 display file Turn-in directory
ID: 3743761 • Letter: C
Question
Chapter IIT Exercise 00 display file Exercice: 00 display file Turn-in directory:600 Files to turn in: Maketile, and files needed for your progran Allowed functions: close, open, read, rite Remarks: n/a . Create a program called ft_display file that displays, on the standard output, only the content of the file given as argument. . The submission directory should have a Makefile with the following rules : all, clean, fclean. The binary will be called ft display file. The nalloc function is forbidden. You can only do this exercise by declaring a fixed-sized array . All files given as arguments will be valid. . Error messages have to be displayed on their reserved outp ./ft_dSaplay-file Makefile display-file.cExplanation / Answer
Elaborating ft_display_file.c
Lets start with the main function first.
1. Initially it will declare a char array (buffer) of 4096 length.
2. ac will be a command line argument. ac contains number of arguments passed to the program.
3. If the number of passed arguments are less than 2, then display a fatal message by calling ft_display_fatal() function with a "file name missing" argument and return code.
4. If the number of passed arguments are greater than 2, then display a fatal message "Too many args" and return some code as well.
5. Only display if the number of arguments are exactly 2.
6. Attempt to open the file in readonlymode and check if it succeeded. It will return code anything other than -1 in case it succeds. If it is -1, then exit the program by returning 1.
7. Call to read function in a loop until the end (rSize = -1). Read function takes 3 parameters, fs is the file descriptor, character array (buffer) and the buffer size. Display each of this character array by calling write() which print the given data to the standard output (console).
8. Finally, close the file and return
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.