I have a char array and I want it to have a certain format, for example:
(first 4 bytes) block type
(next 4 bytes) error code
(next 32 bytes) email address
(next 64 bytes) home address
(next 32 bytes) Full Name
and so forth. About 45 different fields that are padded with 0's to field size. I can use memcpy and advance the pointer each time by the field size but it seems like a tedious task and an ugly code. Maybe a more clever and elegant way to create such a format?
struct?strncpyis for this exactly. It will pad with zeros.chararrays. It sounds like a sruct andstrncpyis exactly what you need here.