I have a C structures in two different machines – server and clients. For example:
struct account {
int account_number;
char *first_name;
char *last_name;
float balance;
};
My question is what are the possible ways to replicate the data between the machines? Maybe I can try to convert the data in XML and copy it? Or I can use arrays?
The simplest, most lightweight solution – if you have a connection open between the two machines in the form of a
FILE*– may be to transmit withfprintfon one end, and decode withfscanfon the other.protocol.h:
sender:
listener:
That may suffice for your four-field struct, but if you anticipate its structure changing or growing significantly it may make sense to pursue XML, JSON, or some other more formal encoding.