Hi,
I am trying to directly cast character pointer to typedef structure which has different types of member.
The value of b is printed as some number which is not as per the value of ptr after 10 character so not sure where the value its printing from.Code:typedef struct { char a[10]; int b; char c[10]; }MyStruct; int main() { char *ptr; MyStruct *pstruct; /* or C style casting: */ memset(&ptr, '\0', sizeof(1972)); ptr = "12394678901234567890testnode123456\0 eventry\0 567\0y8901234567z8"; pstruct = (MyStruct *) ptr; fprintf(stderr, "value of b %u\n", pstruct->b); return 0; }
Can you suggest what could be the problem?
Thanks.