I'm trying to figure out why the functions inperson
and outperson
do not work without prototypes while the function get
does. Outperson
and inperson
works without prototypes if I put them before the main-function but not after. The get-function works both before and after without a prototype. Why?
#include <stdio.h>
struct person {
char name[100];
int age;
};
#define NPERSON 1
int main()
{
//struct person inperson(void);
//void outperson(struct person p);
struct person p[NPERSON];
int i, oldest;
for(i = 0; i < NPERSON; i++) {
p[i] = inperson();
}
oldest = 0;
for(i = 0; i < NPERSON; i++) {
if(p[i].age > p[oldest].age) {
oldest = i;
}
}
outperson(p[oldest]);
get();
return 0;
}
int get()
{
printf("works");
}
struct person inperson(void)
{
struct person p;
scanf("%s %d", p.name, &p.age);
return p;
}
void outperson(struct person p)
{
printf("Person %s, %d years, is oldest\n", p.name, p.age);
}