Secondly, don't do recursive calls to main(). Its bad practice.
Use a switch() to determine the value of sel in main(). It will look better.
this is your main(), tidied up (but not corrected):
Code:
int main(void)
{
/*~~~~~~~~~~~~~~~~*/
int sel;
struct employee emp;
/*~~~~~~~~~~~~~~~~*/
sel = menu();
if (sel == 1)
{
emp = info();
main();
}
if (sel == 2)
{
struct employee emp; /* Whats going on here?! */
}
display(emp);
return 0;
}
Its clear that the if (sel ==2) bit is doing wrong! You cannot redeclare a varible (emp) here, and you wouldn't want to.
This would be a better main():
Code:
int main(void)
{
int sel;
struct employee emp;
while ((sel = menu()) != 0)
{
switch (sel)
{
case 1: emp = info(); break;
case 2: display(emp); break;
default: break;
}
}
return 0;
}
THe display() function prints results now, but I haven't checked it they are correct or not.
Use code tags when posting code please.