Solution for Exercise 19-7
ex1907
#include <stdio.h>
int main()
{
char alphabet[26];
int x;
char *pa;
pa = alphabet; /* initialize pointer */
/* fill the array */
for(x=0;x<26;x++)
{
*pa=x+'A';
pa++;
}
pa = alphabet; /* re-initialize pointer */
/* output the array */
for(x=0;x<26;x++)
{
putchar(*pa);
pa++;
}
putchar('\n');
return(0);
}
Output
ABCDEFGHIJKLMNOPQRSTUVWXYZ
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.
* The char array alphabet is not a string. It doesn't terminate with the null character.
Copyright © 1997-2026 by QPBC.
All rights reserved
