Reputation: 485
I am having a very big data structure. Only 1 structure. Now, this structure has many sub-structures under it and so on. I have to put random values to each variable of this structure. I would have done it manually, but there are more than 10000 variables under it. It's a long and deep structure, that have structure under structure.
for eg -> This is just an example, actual structure is very big
struct qwerty{
unsigned short catch;
unsigned short port;
MediaAuthType_e mediaAuth;
typeShortNatmr NAT;
typeDynEpDom domain;
typeRDomList domainlist;
typeDom domainSize;
};
Now each of these data types has substructure under it eg for MediaAuthType_e data type above we have a structre as
struct MediaAuthType_e
{
int nunkhdr;
msg_body_list* unknown_msg_body;
int unknown_msg_body_count;
SipLssHandle Handle;
InfoEntry *dfo;
char* ua_uri;
char* accept;
void* s_contact;
char* branch;
char* chargeNum;
int 100Supported;
int 100Required;
};
and so on .
Can someone please help? I just have to store random values to each of my variables? Can I automate this process?
EDIT:
Why I am doing this is, I have to encode the data to xdr format and decode it to get the same value
Upvotes: 0
Views: 115
Reputation: 986
Following pseudo code will assign random values. However, the pointers will not be valid pointers! It just fills the whole memory area with sequential values.
unsigned long int i; // in case your structure is too Big!
struct MediaAuthType_e *my_MediaAuthType_e;
my_MediaAuthType_e = malloc(sizeof(struct MediaAuthType_e));
char *tmp = (char *)my_MediaAuthType_e;
for(i = 0; i < sizeof(struct MediaAuthType_e); i++)
{
*tmp = (i%255); // Assign some values at each byte, use your logic to assign random values.
tmp++;
}
Upvotes: 3