• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: using C copy a 1D char array into 2D char array

Resolved: using C copy a 1D char array into 2D char array

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

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
And to output the result array you need to write

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!

arrays c-strings multidimensional-array
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Sort dataframe columns value by close it to another column

27/03/2023

Resolved: PostgreSQL resample 1 minute OHLCV candle data into 5 minute OHLCV candle data

27/03/2023

Resolved: How do I navigate a table without any easily accessible distinctions?

27/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.