One word: "Scope".
If your struct's type is defined is in main()
then the type's scope is main
. Nothing outside main
can know about it. If you want to pass it to another function, obviously that function has to know the type, but if the type is only known in main
then obviously the function can't know about it.
The solution? Move the type's scope to somewhere that both main and the "receiving" function can see it.
Edit: built in types like int
, char
etc already have global scope and so they are known everywhere. What we're dealing with here is a user define type whose scope is limited based on where it is defined.
The same rules apply to variables (aka instances of a type) - a global variable is visible anywhere (I know, you can "hide it" with a local of the same name - lets not split hairs eh ;-), but a local variable in main()
can only be seen inside main()
.