-
structure pointers
Why does'nt this code work I know functions must know about things before they can use them, I thought the prototype did that guess not.
#include<stdio.h>
#include<conio.h>
void details1(struct baby *kayleigh_ptr);
int main()
{
struct baby{
int age;
char name[10];
};
struct baby kayleigh;
struct baby *kayleigh_ptr=&kayleigh;
details1(kayleigh_ptr);
getch();
return 0;
}
void detail1(struct baby *kayleigh_ptr)
{
kayleigh_ptr->age=10;
}
thanks leaner(wanting to ba master).
-
I moved
struct baby{
int age;
char name[10];
};
outside main before the function prototype (so that the structure is global to all functions instead of local to main),
The code then compiled and ran, although it doesn't really do much. Hope that helps!
-
Oh forgot: also need to make prototype match function (detail1 != details1).