I am trying to understand the use of structures with pointers. I wrote the following to learn but it does not work. Please help!
#include <stdio.h>
void my_function(int a, int b, *struct_ptr); /*what is wrong with my function declaration?*/
main()
{
struct MY_STRUCTURE{
int a;
int b;
}element;
struct MY_STRUCTURE *ptr; /*Is this the correct way to create a pointer to the structure? */
element.a = 20;
element.b = 15;
my_function(element.a, element.b, *ptr);
printf("The new values of elements a and b are now: %d and %d\n", element.a, element.b);
return 0;
}
void my_function(int a, int b, *ptr_in)
{
ptr_in ->element.a+=1; /*Is this the correct way to modify a and b in the structure ?*/
ptr_in ->element.b+=1;
}
#include <stdio.h>
void my_function(int a, int b, *struct_ptr); /*what is wrong with my function declaration?*/
main()
{
struct MY_STRUCTURE{
int a;
int b;
}element;
struct MY_STRUCTURE *ptr; /*Is this the correct way to create a pointer to the structure? */
element.a = 20;
element.b = 15;
my_function(element.a, element.b, *ptr);
printf("The new values of elements a and b are now: %d and %d\n", element.a, element.b);
return 0;
}
void my_function(int a, int b, *ptr_in)
{
ptr_in ->element.a+=1; /*Is this the correct way to modify a and b in the structure ?*/
ptr_in ->element.b+=1;
}