pointers - how to create an array of char arrays in arduino -


i need handle data in matrix. want have this:

{{"data11", "data12", "data13"}, {"data21", "data22", "data23"}, {"data31", "data32", "data33"}} 

i think "char* matrix[3][3];" trick, haven't gotten expected result.

i need following actions:

  1. initialize matrix empty (with empty strings or "").
  2. put data in matrix dynamically.

thanks in advance.

you should use character arrays, not pointers string modify contents later.

#include <string.h>  // initialized "" because global variable // please allocate enough memory each elements // (adjust last number [10]if needed) char matrix[3][3][10];  void setup() {   // put data in matrix   strcpy(matrix[0][0], "data11");   strcpy(matrix[0][1], "data12");   strcpy(matrix[0][2], "data13");   strcpy(matrix[1][0], "data21");   strcpy(matrix[1][1], "data22");   strcpy(matrix[1][2], "data23");   strcpy(matrix[1][0], "data31");   strcpy(matrix[1][1], "data32");   strcpy(matrix[1][2], "data33"); }  void loop() { } 

or want use string?

// initialized "" because global variable string matrix[3][3];  void setup() {   // put data in matrix   matrix[0][0] = "data11";   matrix[0][1] = "data12";   matrix[0][2] = "data13";   matrix[1][0] = "data21";   matrix[1][1] = "data22";   matrix[1][2] = "data23";   matrix[2][0] = "data31";   matrix[2][1] = "data32";   matrix[2][2] = "data33"; }  void loop() { } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -