Submitted by Anonymous (not verified) on Sun, 03/10/2013 - 00:55

To help solidify your understanding of this hour's lesson, you are encouraged to answer the quiz questions and finish the exercises provided in the W orkshop before you move to the next lesson. The answers and hints to the questions and exercises are given in Appendix E, "Answers to Quiz Questions and Exercises."
Quiz

    In the following list, which statements are legal?
        char str1[5] = "Texas";
        char str2[] = "A character string";
        char str3[2] = "A";
        char str4[2] = "TX";
    Given a char pointer variable ptr_ch, are the following statements legal?
        *ptr_ch = `a';
        ptr_ch = "A character string";
        ptr_ch = `x';
        *ptr_ch = "This is Quiz 2.";
    Can the puts() function print out the null character in a character array?
    Which format specifier do you use with the scanf() function to read in a string, and which one do you use to read a floating-point number?

Exercises

    Given a character array in the following statement,

    char str1[] = "This is Exercise 1.";

    write a program to copy the string from str1 to another array, called str2.
    Write a program to measure the length of a string by evaluating the elements in the character array one by one. To prove you get the right result, you can use the strlen() function to measure the same string again.
    Rewrite the program in Listing 13.4. This time, convert all uppercase characters to their lowercase counterparts.
    Write a program that uses the scanf() function to read in two integers entered by the user, adds the two integers, and then prints out the sum on the screen.

Related Items

More Examples of Disk File I/O

More Examples of Disk File I/O

The following sections show several more examples of disk file I/O, such as reading and writing binary data and redirecting the standard streams. Three more I/O functions, fscanf(), fprintf(), and freopen(), are introduced, too.

Random Access to Disk Files

Random Access to Disk Files

Exercises : Answer the following Question

To help solidify your understanding of this lesson, you are encouraged to answer the quiz questions and finish the exercises provided in the Workshop before you move to the next lesson.

Question and Answer

    Q What are the differences between a text stream and a binary stream?

Reading and Writing Disk Files

Reading and Writing Disk Files