struct name
        int a;
        char b[10];
        char c;
int main()
        struct name *p;
        p = (struct name *)malloc(3 * sizeof(struct name));
        char *n;
        n = "12345";
        n = (char *)p;
        n = (int*)n;            /*this is not correct . in doubt....change correctly*/
        *(n+sizeof(p->a)+sizeof(p->b)) = 'D';
        *(n+(sizeof(p[0]))) =245678;  /*change this line also*/
        *(n+sizeof(p[0])+sizeof(p->a)+sizeof(p->b)) = 'B';
        *(n+(sizeof(p[0])+sizeof(p[0]))) =233456;     /*change this also*/
        *(n+(2*sizeof(p[0])+sizeof(p->a)+sizeof(p->b))) = 'C';
        printf("n1 = %s %s %c\n",p[0].a,p[0].b,p[0].c);
        printf("n2 = %d %s %c\n",p[1].a,p[1].b,p[1].c);
        printf("n3 = %d %s %c\n",p[2].a,p[2].b,p[2].c);

This is my program..........anyway this is like complex.........its my assignment......almost i finish this program.......what my problem is when i give *n=12345; this line gives output as 45(i.e)by converting into hexadecimal........what i want is watever we give in *n it should print as it is........so we have to TYPECAST on 17th line so how to typecast this and print the same output as in input...........there is a way but i dont know................

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

8 Years
Discussion Span
Last Post by abhimanipal

This is plain stupid.
1. You don't wrap code in code tags
2. You double post.
3. What are you trying to achieve by assigning a (char*) an (int), which is illegal by the way
4. When you say 17th line did you expect me to count all the way when you didn't even bother to wrap this up in code tags?

Your problem is still however not clear at all.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.