Writing to and reading from 2d arrays


I am trying to crate a 2d char array where one dimension is a line to print to a display and the other dimension is the max length of one line.

The relevant part of the code:

char *content[] = {(char *)"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras nulla justo, iaculis sit amet ipsum at, volutpat sodales leo. In vel metus a quam porttitor tempor. Phasellus volutpat hendrerit urna at volutpat. Aenean eget purus mauris. Nam sollicitudin efficitur neque a sagittis. Vestibulum vitae volutpat nibh. Donec commodo ipsum non enim tincidunt, ac tempor ante commodo.",
(char *)"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii ",(char *)"1 1",(char *)"menuitem4",(char *)"menuitem5",};

char* menucontent[100][21];

void textProcessing() {
  int numavailable = 20;
  String temp;
  char buf[20];
  char buf3[20];
  int num = 0;
  for (int i = 0; i < getFound(menu1[selected], ' '); i++){
    temp = getValue(content[selected], ' ', i);
    while (temp.length() > 0) {
      memset(buf, 0, 20);
      if (temp.length() > 20) {
        while (temp.length() > 20) {
          String buf2 = temp.substring(0,18) + "-";
          temp = &temp[18];
          strcpy(menucontent[num], buf);
      if (temp.length() < 20 && temp.length() != 0){
        while (temp.length() < numavailable){
          numavailable -= temp.length()+1;
          strcat( buf3, " ");
          strcat(buf, buf3);
          temp = getValue(content[selected], ' ', i);
        strcpy(menucontent[num], buf);
        numavailable = 20;
      if (temp.length() == 20){
        strcpy(menucontent[num], buf); // Is this possible?
        temp = "";
      Serial.println(menucontent[0]); // Error: "no matching function for call to 'print(char* [21])'"

The main issue i’m having is that I dont understand how exactly the 2d array works and is it possible to print outh the entire entry?
Thank You in advance!

The entire code for those who are curious(the menu part totally works so feel free to use the code ;)): #include <Encoder.h>#include <SPI.h>#include <Wire.h>#include <Adafruit_GF - Pastebin.com

(Using Adafruit feather m0 so memory is no problem)

The documentation is here:

I have obviously read through the documentations and searched for my question on the internet. I even found another thread where it sugested that "Serial.println(menucontent[0]);" would work but it doesn't work.

My question is: Is it possible to print the char array out as a string or do I need to loop through each character and print it out separately?

Thank You.


Got my answer, you can't. Just use structs...

----problem solved----