Coder's Guild Mailing List

re: matrix

Posted by Todd on 2000-05-01

>Firstly, thanks to Fox for help on reducing a string, much appreciated.
>
>Secondly, I cant seem to be able to fill a 5X5 matrix with 25 characters,
>sounds simple but its one of those things |I'll go ''Oh yeah ' to when some
>nice person puts me on the right track.
>
>I have
>
>
>char Matrix[5][5];
>int I, J;
>char StringOfChars[25] = "ABCDEFGHJKLMNOPQRSTUVWXYZ"  ;
>
>/*I know I missed out 'I'*/
>
>for (I = 0; I<5; I++){
>    for (J = 0, J<5; J++{
>       Matrix[I][J] = StringOfChars[I];
>    }
>printf("\n");
>}
>
>/*Where am I going wrong?*/


Okay first of all "I" never gets higher than 5 and never gets to the
assignment past 4. So your highest letter is E.
To correct this, try it this way:

char Matrix[5][5];
int I, J, letter = 0;
char StringOfChars[25] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

for ( I = 0; I < 5; I++)
{
    for ( J = 0; J < 5; J++)
    {
          Matrix[I][J] = StringOfChars[letter];
          letter++;
    }
}

printf("\n");