Skip to main content
Engineering LibreTexts

17.3: Exercises

  • Page ID
    19969
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Below are some quiz questions and suggested projects based on this chapter.

    Questions

    Below are some quiz questions based on this chapter.

    1) What is the end of line character or characters for Linux and Windows?

    2) Based on the explanations in this chapter, what is I/O buffering?

    3) In reference to a high-level language, where are the I/O buffering routines located?

    4) What is the advantage of hiding the I/O buffering complexity from the programmer?

    5) What is the key advantage of performing I/O buffering (as opposed to reading one character at a time)?

    6) Why is it difficult to use the file read system service to read one text line from a file?

    7) In terms of the memory hierarchy, why is buffering advantageous?

    8) In terms of system overhead, why is buffering advantageous?

    9) Why does the file read buffering algorithm require statically declared variables?

    10) How is the end of file recognized by the program?

    11) Provide one, of many, reasons that a file read request might return an error even when the file has been opened successfully.

    12) What must be done to address the case when the file size is an exact multiple of the buffer size?

    13) Why is the maximum length of the text line passed as an argument?

    14) How does the presented algorithm ensure that the very first call the myGetLine() will read the buffer?

    Suggested Projects

    Below are some suggested projects based on this chapter.

    1) Refine the presented algorithm to address maximum text line check and possibility that the file size is an even multiple of the buffer size. This includes formalizing the variable names and looping constructs (many possible choices).

    2) Create a simple main program that will test the myGetLine() function by opening a file, calling the myGetLine() function, and displaying the lines to the console. Test the program with a series of different size files including ones smaller, larger, and much larger than the selected buffer size. Capture the program output and compare the captured output to the original file to ensure your program is correct.

    3) Create a program that will read two file names from the command line, read lines from the first file, add line numbers, and write the modified line (with the line number) to the second file. For example, your add lines program might be initiated with:

               ./addLine inFile.txt newFile.txt
    

    where the inFile.txt exists and contains standard ASCII text. If the inFile.txt file does not exist an error should be generated and the program terminated. The program should open/create the file newFile.txt and write the lines, with the line numbers, to the newFile.txt file. The output file should be created, deleting an old version if one exists. Use a text editor to verify that the line numbers track correctly in the output file.


    This page titled 17.3: Exercises is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Ed Jorgensen.

    • Was this article helpful?