CS 105: C++
Quiz 7 Requirements
C: Chapter 7

  1. Understand the basics of input and output redirection as described in the reading, including what ">", "<", and "|" do.

  2. Be able to write simple scanf statements to read things like ints, floats, and strings.  Important: How can scanf save what it reads into your variables if all function calls in C are pass by value?  Does this work the same for scanf reading into ints as it does for reading into strings?  (Even more important: If you handle this wrong, bad things can happen.)

  3. What is sprintf?  What is the simple change required to turn a printf statement into an analogous sprintf statement?  (Note: In my experience, sprintf is very useful.)

  4. Is there something similar for scanf?

  5. Be able to fill in the blanks below so that the word "test" is written into the file "test.txt", and understand the purpose of each line.

      ____ *fp;                 /* Declare the file pointer. */
      fp = fopen(____, ____);   /* Open the file for writing. */
      fprintf(____, "test\n");  /* Write the text to the file. */
      ____(fp);                 /* Close the file. */
  6. Understand how fprintf is useful in error handling.  (What can it do that printf can't?)  Also, how can you rewrite any printf call as a call to fprintf?

  7. What does "exit" do, and why is it necessary?  (What can it do that returning from main cannot?)

  8. What does "system" do?  (Note: In my opinion, system is also very useful.)

  9. Understand the basics of malloc and calloc, including what they do and how they differ.  How is "sizeof" commonly used in calloc calls?  "free" is used to undo the work of malloc; is "free" used in the same way with respect to calloc?

  10. Know how to use rand() to write an expression that produces a random integer between 1 and 10 (inclusive).  (Note: You'll probably need to use "%" and "+", and your first guess may not be correct.)

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.