(Solved!Thanks!)Saving a long type of array to a String array

Hello,I'm new to arduino and im a complete beginner to programming, is it possible to store a long type of data to a string array?
such an example = a id number is 123456, b id number is 456789, c id number is 098765
Can some one show me the correct way to do it?

Thanks :slight_smile:

123.PNG

Firstly let's deal with the data types. In your post you talk about strings (zero terminated array of chars) but the paltry lines of code that you posted show you using Strings (objects created using the String library) They are not the same thing.

Now, what is it that you want to do ? When you have stored a long type to string or String array what will the array look like ?

Basically i want to make a 4x2 array i tried using int myArray[4][2] = {{Name,ID}{A,123456}{B,456789}{C,098765}} but it shows error. What type of command should i use?

Also be aware that array elements are numbered from zero, not from one.

https://www.arduino.cc/en/Tutorial/StringConstructors shows examples of constrctors with numbers.

Remarks:

  1. The use of String (capital S) can result in memory fragmentation.
  2. Why do you want to store as string or String? It wastes memory.

bloatedduck:
Basically i want to make a 4x2 array i tried using int myArray[4][2] = {{Name,ID}{A,123456}{B,456789}{C,098765}} but it shows error. What type of command should i use?

You can use a struct or a class.

struct DETAILS
{
  char Name[16];
  long Id;
};

DETAILS people[] =
{
  { "piet", 12345},
  {  "klaas", 67890}
};

You can access Name with e.g. people[0].Name and Id with e.g. people[0].Id .
Note that Id is still a long, not a string or String.

Thankyou for your help! im gonna try it out now :slight_smile:

Be aware that the maximum size for Name is 15 characters; the 16th one is for the nul terminator.