Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: Double char array

  1. #1
    Senior Member
    Join Date
    Jan 2015
    Location
    France
    Posts
    114

    Double char array

    Hello,

    It's look like we can't do this with arduino/teensy ?

    Code:
    char Nom[10][20]={"Paris","Marseille","Lyon","Rennes","Toulouse","Strasbourg","Grenoble","Lille","Nantes","Bordeaux"};
    Or do I miss something ?

    Thank you,
    Manu

  2. #2
    Senior Member
    Join Date
    Jan 2015
    Location
    France
    Posts
    114
    In fact it work, but compiler complain ;-)

    Is there another way to do this ?

    the goal is to call a string in regard with a number.

  3. #3
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,416
    Code:
    char *Nom[10]={"Paris","Marseille","Lyon","Rennes","Toulouse","Strasbourg","Grenoble","Lille","Nantes","Bordeaux"};
    or
    Code:
    char *Nom[]={"Paris","Marseille","Lyon","Rennes","Toulouse","Strasbourg","Grenoble","Lille","Nantes","Bordeaux"};
    Pete

  4. #4
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,416
    You then refer to the i'th element as Nom[i].
    Serial.println(Nom[2]) would print
    Lyon

    Pete

  5. #5
    Senior Member
    Join Date
    Apr 2020
    Location
    DFW area in Texas
    Posts
    118
    Quote Originally Posted by Manu View Post
    In fact it work, but compiler complain ;-)

    Is there another way to do this ?

    the goal is to call a string in regard with a number.
    Manu:

    What specific complaint do you get from the compiler ?? Can you attach the source for your sketch ?? These details may make it easier to assist.

    Mark J Culross
    KD5RXT

  6. #6
    Senior Member
    Join Date
    Jan 2015
    Location
    France
    Posts
    114
    Hi,

    I'm sorry, it was a code error. I placed this definition in a "switch/case" case and it complain (and break the switch/case choices).
    I then moved the definition in a function that is called by the "case" and all is now OK.

    I'm sorry for the trouble,
    Manu

  7. #7
    Senior Member
    Join Date
    Mar 2016
    Posts
    198
    ISO C++ is way picky about string constant to char * conversion. Just a warning in GCC -fpermissive.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •