I have a structure that is an array (struct tag my_struct[10]). I am trying to pass a pointer to that structure to a function (void myfunction(struct tag *p)). Inside the function I try to reference the pointer to the structure. It works well for (p->.value) which points to mystruct[0].value, but I can not figure how to access the other array values (such as my_struct[1].value or my_struct[2].value, because I get an error if I attempt to use p[1]-> value = 1 or *(p+1)-> value =1, etc and the like.
code sample:
#include <stdio.h>
#include <string.h>
struct tag{
char suit;
int value;
};
struct tag my_struct[5];
void shuf(struct tag *p);
int main(void)
{
shuf(my_struct);
printf(" %d : %c \n" , my_struct[0].value, my_struct[0].suit);
printf(" %d : %c \n" , my_struct[1].value, my_struct[1].suit);
return (0);
}
void shuf(struct tag *p)
{
p-> suit = 'h'; /* works: assess my_struct[1]*/
p-> value = 18; /* same */
p[1]-> suit = 'w'; /* gets an error */
}
Error: E2288 - pointer to structure required on left side of -> or ->* in function shuf(tag *).
Does anyone know of a way to do what I'm attempting to do.
code sample:
#include <stdio.h>
#include <string.h>
struct tag{
char suit;
int value;
};
struct tag my_struct[5];
void shuf(struct tag *p);
int main(void)
{
shuf(my_struct);
printf(" %d : %c \n" , my_struct[0].value, my_struct[0].suit);
printf(" %d : %c \n" , my_struct[1].value, my_struct[1].suit);
return (0);
}
void shuf(struct tag *p)
{
p-> suit = 'h'; /* works: assess my_struct[1]*/
p-> value = 18; /* same */
p[1]-> suit = 'w'; /* gets an error */
}
Error: E2288 - pointer to structure required on left side of -> or ->* in function shuf(tag *).
Does anyone know of a way to do what I'm attempting to do.