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 goto Statement

The goto Statement

The continue Statement

The continue Statement

The break Statement

The break Statement

You can add a break statement at the end of the statement list following every case label, if you want to exit the switch construct after the statements within a selected case are executed.

The switch Statement

The switch Statement

Nested if Statements

Nested if Statements

As you saw in the previous sections, one if statement enables a program to make one decision. In many cases, a program has to make a series of decisions. To enable it to do so, you can use nested if statements.