S
Santa
Hello:
I am trying to manipulating the data from the pointer (the below
program) in the function "test1", Is there any best way of changing
the data from that pointer (I am changing by assigning the address
"&p2->x" to a poiner and then changing. Looklike this is not perfect,
can somebody correct me. My programn is below. Thanks,
==============================================================
#include <stdio.h>
typedef struct xyz
{
int x;
int y;
int z;
}xyz_t;
main()
{
xyz_t p1;
p1.x = 1;
p1.y = 2;
p1.z = 3;
printf("First time: %d %d %d\n",p1.x, p1.y, p1.z); //It should print 1
2 3
test1(&p1);
printf("Second time time: %d %d %d\n",p1.x, p1.y, p1.z); //It should
print 10 20 30
}
void
test1(xyz_t *p2)
{
int *p3;
p3 = &p2->x;
*p3 = (int)10;
p3 = &p2->y;
*p3 = (int)20;
p3 = &p2->z;
*p3 = (int)30;
}
I am trying to manipulating the data from the pointer (the below
program) in the function "test1", Is there any best way of changing
the data from that pointer (I am changing by assigning the address
"&p2->x" to a poiner and then changing. Looklike this is not perfect,
can somebody correct me. My programn is below. Thanks,
==============================================================
#include <stdio.h>
typedef struct xyz
{
int x;
int y;
int z;
}xyz_t;
main()
{
xyz_t p1;
p1.x = 1;
p1.y = 2;
p1.z = 3;
printf("First time: %d %d %d\n",p1.x, p1.y, p1.z); //It should print 1
2 3
test1(&p1);
printf("Second time time: %d %d %d\n",p1.x, p1.y, p1.z); //It should
print 10 20 30
}
void
test1(xyz_t *p2)
{
int *p3;
p3 = &p2->x;
*p3 = (int)10;
p3 = &p2->y;
*p3 = (int)20;
p3 = &p2->z;
*p3 = (int)30;
}