Well, the best way to access the serial number is probably to copy it to a separate buffer using strncpy .
#include <string.h> ... char family; char serial[7]; // Extra byte for null terminator char checksum; ... family = ROM_CODE[0]; strncpy(serial, &ROM_CODE[1], 6); serial[6] = '\0'; checksum = ROM_CODE[7]; ...
&ROM_CODE[1] you need to find the address of the second element in ROM_CODE . ROM_CODE+1 may also work, but my C is a rusty touch.
Zero ('\ 0') is added at the end, because C uses null-terminated strings . This will ensure compatibility with C library routines and commonly used C idioms.
You can also access it directly from the array. But it will be harder to work with and is hardly worth it unless you really need that 6 bytes of memory.
Depending on how complex your application is, you can wrap this in a class. Pass the 8-character buffer to the constructor, and then use methods like getFamily() / getSerial() to get the information you need.
For a very simple application, however, there is a lot of extra code to simplify something that is already very manageable.
source share