Home > Net >  why isn't this code storing the words in this 2d array?
why isn't this code storing the words in this 2d array?

Time:09-15

The code is suppose to take in 6 words starting with a, b or c and put them in to each respective array. Only problem is that it doesn't store anything at all no matter what I do. The printf in the last part of the code is suppose to spit everything that I typed in out but it's giving me nothing but blanks...

#include <stdio.h>
int main()
{
char startswithA[6][10] = {};
char startswithB[6][10] = {};
char startswithC[6][10] = {};
char holder[6][10] = {};

printf("Enter a word starting with a, b or c (write 2 of each)\n");
for (int i = 0; i < 6; i = i   1)
{
    printf("Now entering word #%d\n", i 1);
    scanf_s("%s", &holder[i]);
    if(holder[i][0] == 'a')
    {   
        for(int a = 0; a < 10; a = a   1)
        {
            holder[i][a] = startswithA[i][a];
        }
    }
    else if (holder[i][0] == 'b')
    {
        for(int a = 0; a < 10; a = a   1)
        {
            holder[i][a] = startswithB[i][a];
        }
    }
    else if (holder[i][0] == 'c')
    {
        for(int a = 0; a < 10; a = a   1)
        {
            holder[i][a] = startswithC[i][a];
        }
    }
    else
    {
        printf("something out of bound was typed in");
    }
}
for(int b = 0; b < 6; b = b   1)
{
    printf("%s %s %s\n", startswithA[b], startswithB[b], startswithC[b]);
}

return 0;
}

CodePudding user response:

Looks like it is typo

holder[i][a] = startswithA[i][a];

Did you mean?

startswithA[i][a] = holder[i][a];
  •  Tags:  
  • c
  • Related