Question:
I am trying to copy a 1D array of Strings into a 2D array of strings in C.I was able to achieve this with integer enter image description here
for(i=0; i<3; i++) { for(j=0; j<3; j++) printf("%s ", d[i][i]); ^^^^^^^ printf("\n"); } [/code]
As for your last program then it can look like#include
#include
int main( void )
{
char d[3][3][8] ={0}; // Destination array
char s[9][8]={“orange”,”apple”,”table”,”chair”,”cable”,”TV”, “124”,”HI”}; // Source 1 Day array
for( size_t i = 0; i < 3; i++ ) { for ( size_t j = 0; j < 3;j++ ) { strcpy( d[j][i], s[3 * i + j] ); } } for ( size_t i = 0; i < 3; i++ ) { for ( size_t j = 0; j < 3; j++ ) { printf( "%s ", d[i][j] ); } putchar( '\n' ); } return 0; } [/code]
If you have better answer, please add a comment about this, thank you!