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

The #define and #undef Directives

The #define and #undef Directives

The #define directive is the most common preprocessor directive, which tells the preprocessor to replace every occurrence of a particular character string (that is, a macro name) with a specified value (that is, a macro body).

The C Preprocessor Versus the Compiler

The C Preprocessor Versus the Compiler

One important thing you need to remember is that the C preprocessor is not part of the C compiler.

What Is the C Preprocessor?

If there is a constant appearing in several places in your program, it's a good idea to associate a symbolic name to the constant, and then use the symbolic name to replace the constant throughout the program. There are two advantages to doing so. First, your program will be more readable.

Exercises : Answer the following Question

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 Workshop before you move to the next lesson.

Question and Answer

    Q Why is random access to a disk file necessary?