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 !

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];

thanks but running the code would give incompatible assign types

temp[0] = letter; solves it =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.