I'm having a little trouble passing values from a structure to a function using pointers.
I have defined a structure as such:
Code:
struct Struct1 {
short Shrt1;
long Lng1;
char Array1[60];
double Doub1;
};
Then tried to declare a instance of this structure and a pointer to that as such:
Code:
struct Struct1 inst1;
struct Struct1 *ptr;
ptr=&inst1;
I have then tried to pass values to a function and use them like this:
Code:
void function1(ptr)
{
printf("\nShort integer 1: %d", ptr->Shrt1);
printf("\nLong integer 1: %L", ptr->Lng1);
printf("\nCharacter Array 1: %s", ptr->Array1);
printf("\nDouble Precision Number 1: %d", ptr->Doub1);
return;
}
But I am getting an error saying that ptr is an invalid type argument. Any ideas where i'm going wrong? Do I need to post more of the code? should function use *ptr instead of ptr as an argument? I'm quite new to C and having trouble getting my head around the correct way to use pointers.