Hi All.
I'm struggling to get back to grips with C following a 15 year absence...
I have a structure, as follows:-
And I want to populate it through a function/procedure by passing it to the function along with some variables as follows:-Code:typedef struct { long mtype; int useragent; time_t mdatetime; char mtext[4096]; } busMessage;
But when I use this function in the following way:-Code:void buildMessage( busMessage BM, long MT, int UA ) { BM.mtype = MT; BM.useragent = UA; BM.mdatetime = 1005454; strcpy(BM.mtext, "A test"); }
.... all the fields in myMessage are zero.Code:int main(void) { busMessage myMessage; buildMessage (myMessage, 4, 4); printMessage (myMessage); exit(0); }
The function printMessage just does this:-
I have a funny feeling this may be a scope issue(?) but can't quite get my head around it.Code:void printMessage( busMessage BM ) { printf(ctime(&BM.mdatetime)); // Prints 1st Jan 1970 (correct, as mdatetime must be 0) printf("Time as int : %d\n", BM.mdatetime); // Zero printf("UA as int : %d\n", BM.useragent); // Zero printf("MT as int : %d\n", BM.mtype); // Zero printf("Payload : %s\n", BM.mtext); // Blank }
Any help would be gratefully received!
Thanks.



LinkBack URL
About LinkBacks





.