Hi i am quite new into programming and i need some small help on converting char array to string and i am not sure where has gone wrong. i need to get user input in %c and i input for the first input - aabcc and then clicks on enter the second input - fsdff then enter again 3rd input - rewrr then enter again 4th input - zzxcc and enter again the last input - asdfg.
But the outputs gives me array 1 = aabcc , 2nd array = fsdf (one of gone missing) 3rd array = f '\n' ... followed by 3rd 4th and 5th array displayed incorrectly. Thanks all in advanced.
int main()
{
int i, j;
char ch[5][6];
char c[5][5];
for (i = 0; i < 5; i++)
for (j = 0; j<5; j++)
scanf("%c", &c[i][j]); // get user input
memcpy(ch[0], c[0], 5);
ch[0][5] = '\0';
memcpy(ch[1], c[1], 5);
ch[1][5] = '\0';
memcpy(ch[2], c[2], 5);
ch[2][5] = '\0';
memcpy(ch[3], c[3], 5);
ch[3][5] = '\0';
memcpy(ch[4], c[4], 5);
ch[4][5] = '\0';
printf("array 1 = %s, array 2 = %s , array 3 = %s , array 4 = %s , array 5 = %s ", ch[0], ch[1], ch[2], ch[3], ch[4]);
}