Solution for Exercise 19-7

ex1907

#include <stdio.h>

int main()
{
    char alphabet[27];
    int x;
    char *pa;

    pa = alphabet;      /* initialize pointer */

/* Fill array */
    for(x=0;x<26;x++)
    {
        *pa=x+'A';
        pa++;
    }

    pa = alphabet;

/* Display array */
    for(x=0;x<26;x++)
    {
        putchar(*pa);
        pa++;
    }
    putchar('\n');

    return(0);
}

Notes

* Another way to fill the array with letters A to Z could look like this:

Then you would use the statement *pa=x; within the loop to fill the array elements.

* Of course, you're not really working with letters in your code. The compiler translates 'A' into that character's ASCII code value, 65. Refer to Appendix A in the book for a list of ASCII code values.