#include<stdio.h>
#include<stdlib.h>
#include<string.h>
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*/
        strcpy(n+(sizeof(p->a)),"ALL");
        *(n+sizeof(p->a)+sizeof(p->b)) = 'D';
        *(n+(sizeof(p[0]))) =245678;  /*change this line also*/
        strcpy((n+sizeof(p->a)+sizeof(p[0])),"IS");
        *(n+sizeof(p[0])+sizeof(p->a)+sizeof(p->b)) = 'B';
        *(n+(sizeof(p[0])+sizeof(p[0]))) =233456;     /*change this also*/
        strcpy((n+(2*sizeof(p[0])+sizeof(p->a))),"WELL");
        *(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................

Recommended Answers

All 2 Replies

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.

What is the objective of your assignment ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.