Why is this code only assigning the ascii value to the arrray. I want it to print out the letters ex:
array element 0= a
array element 1 = b
what Am i doing wrong.?
Here are the two scripts i coded. I thought the second would work, but it didn't. I was so excited to wake up this morning cause i thought i had solved it but .....
Code:
code 1
/* alpaarray.c intializes a 26 element array to the ltrs of the alphabet and
* displays it */
#include<stdio.h>
#define SIZE 26
int main(void)
{
int ndx;
char alphabet[SIZE];
char ltr;
/* outer loop to count to 26 */
for (ndx = 0; ndx < SIZE; ndx++)
{
for (ltr = 'a'; ltr <= ('a' + ndx); ltr ++)
alphabet[ndx] = ltr;/* assigning only ascii value */
printf("Alphabet element number %3d is %3d\n", ndx, alphabet[ndx]);
}
getchar();
return (0);
}
Code:
/* ltrarray2.c intialises a character array to ltr of the alphabet */
#include <stdio.h>
#define SIZE 26
int main(void)
{
int row;
char alpha[SIZE], ltr;
/* set up rows */
for (row = 0, ltr = ('a' + row); row < SIZE; row++,ltr++)
alpha[row] = ltr;
/* print elements of row */
for (row = 0; row < SIZE; row++)
printf("Element %3d of Alpha array is %3d\n", row, alpha[row]);
getchar();
return (0);
}