Creation of a DB with longs and strings

Hello, for a project, I need to create a database in matrix format, in which some strings are stored based on a 4-byte identifier, the database would be like this:

"4bytes" BD_Num[2] = {
  0x0011AAEE,
  0x2233CCFF
}
"28Chars" BD_Val[2] = {
  "hello",
  "goodbye"
}

and the operation would be something like this:

1.- I receive an identifier
2.- with a for loop I look for it in BD_Num[]
3.- based on the number that I have obtained, I return the value of BD_Val[]

My problem is space, I have plenty of processing time, I can afford to do that "thing", but I need to be able to limit the volume of data

For the identifier I need 4Bytes, which for example in an arduino uno is a long, but I understand that in an arduino a long is worth 8bytes (I'm not sure), how can I define an unsigned integer of exactly 4bytes?

On the other hand, for the string, I need to limit it to 28 characters maximum, I think it can be done using a char array instead of a normal string, but I don't know how to make it not overflow, any ideas?

I would appreciate any answer :slight_smile:

Hello arixtoteles09

Take some time and study the use of arrays, structures and structured array.

https://www.learncpp.com/

Have a nice day and enjoy coding in C++.

It's 4 bytes, but if you use types like int etc the length can vary depending on the platform.

uint32_t someVariable; // will be 4 bytes

u means unsigned
int means integer
32 means 32 bits (4 bytes)
_t means type

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.