0

i got a little question hope you guys can help out

i wanna copy a char array[8] to a 2D array , strcpy doesn't let me do it. how should i go about

char letter[8]="abcdefg";
char temp[10][2];

for(int i=0;i<10;i++)
strcpy(temp[i],letter[i])

how do i get extract all the letters into the 2D array ?
so that
temp[0]=a
temp[1]=b
temp[2]=c
etc... thanks !

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by tropical08
0

copy it one letter at a time, like this and also the loop needs to stop when end-of-string null terminator is found in the letter array.

char letter[8]="abcdefg";
char temp[10][2] = {0};

for(int i=0; letter[i] != 0;i++)
   temp[i] = letter[i];
0

thanks but running the code would give incompatible assign types

temp[0] = letter; solves it =)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.