Please Help Me

Joined
May 20, 2010
Messages
4
Reaction score
0
1.
#include<stdio.h>
2.
#include<stdlib.h>
3.
#include<string.h>
4.
struct name
5.
{
6.
int *a;
7.
char b[10];
8.
char c;
9.
};
10.
int main()
11.
{
12.
struct name *p;
13.
p = ( struct name * ) malloc ( 3 * sizeof ( struct name ) );
14.
char *n;
15.
n = ( char * ) p;
16.

17.
*n = 275;
18.
strcpy ( n + ( sizeof ( p->a ) ), "ALL" );
19.
* ( n + sizeof ( p->a ) + sizeof ( p->b ) ) = 'D';
20.

21.
* ( n + ( sizeof ( p[0] ) ) ) = 245;
22.
strcpy ( ( n + sizeof ( p->a ) + sizeof ( p[0] ) ), "IS" );
23.
* ( n + sizeof ( p[0] ) + sizeof ( p->a ) + sizeof ( p->b ) ) = 'B';
24.

25.
* ( n + ( sizeof ( p[0] ) + sizeof ( p[0] ) ) ) = 233;
26.
strcpy ( ( n + ( 2*sizeof ( p[0] ) + sizeof ( p->a ) ) ), "WELL" );
27.
* ( n + ( 2*sizeof ( p[0] ) + sizeof ( p->a ) + sizeof ( p->b ) ) ) = 'C';
28.

29.
printf ( "n1 = %d %s %c\n", p[0].a, p[0].b, p[0].c );
30.
printf ( "n2 = %d %s %c\n", p[1].a, p[1].b, p[1].c );
31.
printf ( "n3 = %d %s %c\n", p[2].a, p[2].b, p[2].c );
32.
}

This is the program.........u know in line 17 *n =275 will give the output as 19.........here i want to print as 275 what will be the changes should be done to print 275.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top