How to select terms from a list?

Dear, I have some rows with five columns, like this:

101, peter duck frasson, EM1,123456789,3233343536373839
.
117, james frank gemerson, ED0,987654321,22133434536573869
.
etc

I can create an unsigned long list[50][5]
or a char

When I type 117, for example, I need to see on the serial monitor only field 2 and field 3 of line 117, which in the example above would be:

james frank gemerson, ED0

I still don't have a code, but I wonder what would be the example of the code snippet that gives this result?

117 could be a String, Example: String Value

If(value == 117) {
Serial.println(xxx);
}

But all 5 fields in the list can have varying amounts of characters, longer or shorter names, etc.

Do you have an example that I can see how it was done and then try to follow?

Grateful

consider

output:

dispRecords
  101   EM1 123456789 3233343536373839 peter duck frasson
  117   ED0 987654321 22133434536573869 james frank gemerson
findName: peter
  101   EM1 123456789 3233343536373839 peter duck frasson
findName: george
findName: no match
 none
findName: frank
  117   ED0 987654321 22133434536573869 james frank gemerson

code:

struct Record {
    int         id;
    const char *sym;
    long        val0;
    const char *str;
    const char *name;
};

Record records [] = {
    { 101, "EM1", 123456789, "3233343536373839",  "peter duck frasson" },
    { 117, "ED0", 987654321, "22133434536573869", "james frank gemerson" },
};
const unsigned Nrecord = sizeof(records) / sizeof(Record);

char s [80];

// -------------------------------------
void
dispRecord (
    Record *r )
{
    if (NULL == r)
        sprintf (s, " none");
    else
        sprintf (s, " %4d %5s %lu %15s %s",
                r->id, r->sym, r->val0, r->str, r->name);
    Serial.println (s);
}

// -------------------------------------
void
dispRecords (void)
{
    Serial.println (__func__);
    Record *r = records;
    for (unsigned n = 0; n < Nrecord; n++, r++)
        dispRecord (r);
}

// -------------------------------------
Record *
findName (
    const char *name )
{
    sprintf (s, "%s: %s", __func__, name);
    Serial.println (s);

    Record *r = records;
    for (unsigned n = 0; n < Nrecord; n++, r++)  {
     // if (! strncmp (r->name, name, strlen(name)))
        if (strstr (r->name, name))
            return r;
    }

    sprintf (s, "%s: no match", __func__);
    Serial.println (s);
    return NULL;
}

// -----------------------------------------------------------------------------
void setup () {
    Serial.begin (115200);

    dispRecords ();

    dispRecord (findName ("peter"));
    dispRecord (findName ("george"));
    dispRecord (findName ("frank"));
}

void loop (void)
{
}

Friend, I will try to study line by line to understand what you did.

But in my case it wouldn't be FindName. I will always locate by numerical code, 101, 117, etc.

Greetings.

As @gcjr demonstrated a "struct" is what to use to store data of differing types that are related.

there can always be findId(), findSym(), ... of course it's easier to match integers (e.g ==) than strings.

variable types can also be different, val0 can also be a char*

DedoPositivo

Are these 'rows' lines in a text file on an SD card? If not, how are these rows represented in the Arduino?

  String row = "117, james frank gemerson, ED0,987654321,22133434536573869";
  String value = "117"

  if (row.startsWith(value + ','))
    ShowData(row);
}

void ShowData(String &row)
{
  size_t nameIndex = row.indexOf(',') + 1;
  size_t nameEnd = row.indexOf(',', nameIndex);
  String name = row.substring(nameIndex, nameEnd);

  size_t dataIndex = row.indexOf(',', nameEnd+1) + 1;
  size_t dataEnd = row.indexOf(',', dataIndex);
  String data = row.substring(dataIndex, dataEnd);

  Serial.println(name + ", " + data);
}

I still don't have a code. I was thinking about starting. But it will stay inside the sketch

I have no idea what you mean. Please explain

i think he may be saying he hasn't started writing any code yet (nor has an idea of how to do what's asked)

Perfect. I am trying to learn. I'm already out of zero, I think. But there is still a long way to go.

Thank you to those who gave intelligent and constructive responses.

To the others, a hug and see you soon.

know that feeling. never heard it put that way before

Live and learn my dear. When you're older you'll see that you've never seen many things.

But who wants to help with the theme of the topic and returning to it, I was thinking, if I have 50 lines, each line with 5 fields. Why can't I use
unsigned long list[50][5]

and then fetch the fields with:

int x,y;

Serial.println(String(list[x][y]));

Because it could never print any names?

didn't realize all your fields were text. not sure about String

output

dispLsts
  101   EM1    123456789 3233343536373839 peter duck frasson
  117   ED0    987654321 22133434536573869 james frank gemerson
findId: 101
  101   EM1    123456789 3233343536373839 peter duck frasson
findId: 100
findId: no match
findId: 117
  117   ED0    987654321 22133434536573869 james frank gemerson
const char *  lst [][5] = {
    { "101", "EM1", "123456789", "3233343536373839",  "peter duck frasson" },
    { "117", "ED0", "987654321", "22133434536573869", "james frank gemerson" },
};
const unsigned Nrecord = 2;

char s [80];

// -------------------------------------
void
dispLst (
    int idx )
{
    if (0 <= idx)  {
        sprintf (s, " %4s %5s %12s %15s %s",
            lst [idx][0], lst [idx][1],
            lst [idx][2], lst [idx][3], lst [idx][4]);
        Serial.println (s);
    }
}

// -------------------------------------
void
dispLsts (void)
{
    Serial.println (__func__);
    for (unsigned n = 0; n < Nrecord; n++)
        dispLst (n);
}

// -------------------------------------
int
findId (
    const char *id )
{
    sprintf (s, "%s: %s", __func__, id);
    Serial.println (s);

    for (unsigned n = 0; n < Nrecord; n++)  {
        if (! strcmp (lst [n][0], id))
            return n;
    }

    sprintf (s, "%s: no match", __func__);
    Serial.println (s);
    return -1;
}

// -----------------------------------------------------------------------------
void setup () {
    Serial.begin (115200);

    dispLsts ();

    dispLst (findId ("101"));
    dispLst (findId ("100"));
    dispLst (findId ("117"));
}

void loop (void)
{
}

Alright guys, thank you to everyone who participated. With what was posted here, I will continue my study and if more doubts arise, I'll come back here this time with some code.

What I wanted is just to have the freedom to choose fields (columns) from a list using the code as a reference (110,117,101...) of the line.

And print any fields, 1 field, or more fields, both in the serial and in an SD card for example. Be it numbers or texts.

So I would have only 1 table inside the Sketch and from it I would take the desired fields, which, sometimes, could be some, sometimes they could be others.

Greetings.

Because your fields are not all integers below 4.2 billion.

Have you got any control over the values of the reference numbers ?

dear john,

I've advanced a bit with your code. I put in a 4x3 keyboard and created a ROW string with three lines starting with 0,1, and 1000.

I put a little BIP just to accompany the keyboard keys.

What I would like is: When I type 0, I see in the MonitorSerial data only from line 0 printed including 0. I then select which fields among the 5 fields each line has.

When I type 1 on the keyboard, I only see data from row 1.

And when I type 1000 I only see data from line 1000.

How would the code look to do this ?

= I'm using an ESP32 as that's what I have available here at the moment.

#include <Tone32.h>
#include <Keypad.h>

#define ROW_NUM     4
#define COLUMN_NUM  3

char keys[ROW_NUM][COLUMN_NUM] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};

byte pin_rows[ROW_NUM] = {36, 39, 34, 35};
byte pin_column[COLUMN_NUM] = {32, 14, 12};

Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );

const int buzzer = 13;
String row = 
"0,james frank gemerson,ED0,987654321,22133434536573869
1,samuel vick leman,EM1,123456789,0001234
1000,lee bronx massa,EF2,24681357,11223344556677";

String value = "";

void setup() {
  Serial.begin(115200);
  pinMode(buzzer, OUTPUT);

//  if (row.startsWith(value + ',')) {
//    ShowData(row);
//  }
}

void loop() {
  char key = keypad.getKey();
  
  if (key) {
    value += key;
    Serial.println(value);
    tone(13,440,70,0);
  }

  if (key == '*') {
    value = "";
  }
  
  if (value == "120") {  
    ShowData(row);
    value = "";
  }

}

void ShowData(String &row)  {
  
  size_t idIndex = row.indexOf(',') - 3;
  size_t idEnd = row.indexOf(',', idIndex);
  String id = row.substring(idIndex, idEnd);

  size_t dataIndex = row.indexOf(',', idEnd + 0) + 1;
  size_t dataEnd = row.indexOf(',', dataIndex);
  String data = row.substring(dataIndex, dataEnd);

  Serial.println(id + ", " + data);



//  size_t nameIndex = row.indexOf(',') + 1;
//  size_t nameEnd = row.indexOf(',', nameIndex);
//  String name = row.substring(nameIndex, nameEnd);

//  size_t dataIndex = row.indexOf(',', nameEnd+1) + 1;
//  size_t dataEnd = row.indexOf(',', dataIndex);
//  String data = row.substring(dataIndex, dataEnd);

//  Serial.println(name + ", " + data);
}