Programming in C

(Barry) #1
Exercises 277


  1. Write a function called sort3to sort three integers into ascending order. (This
    function is not to be implemented with arrays.)

  2. Rewrite the readLinefunction from Chapter 10 so that it uses a character pointer
    rather than an array.

  3. Rewrite the compareStringsfunction from Chapter 10 to use character pointers
    instead of arrays.

  4. Given the definition of a datestructure as defined in this chapter, write a function
    called dateUpdatethat takes a pointer to a datestructure as its argument and that
    updates the structure to the following day (see Program 9.4).

  5. Given the following declarations:


char *message = "Programming in C is fun\n";
char message2[] = "You said it\n";
char *format = "x = %i\n";
int x = 100;

determine whether each printfcall from the following sets is valid and produces
the same output as other calls from the set.
/*** set 1 ***/
printf ("Programming in C is fun\n");
printf ("%s", "Programming in C is fun\n");
printf ("%s", message);
printf (message);

/*** set 2 ***/
printf ("You said it\n");
printf ("%s", message2);
printf (message2);
printf ("%s", &message2[0]);

/*** set 3 ***/
printf ("said it\n");
printf (message2 + 4);
printf ("%s", message2 + 4);
printf ("%s", &message2[4]);

/*** set 4 ***/
printf ("x = %i\n", x);
printf (format, x);
Free download pdf