Sunday, August 2, 2009

How to end my program if exit() and _exit() doesn't work? (C Program)?

The program was supposed to close after the user chose 'save and exit' but it goes to 'browse' after the data was saved. Here's the code of my 'main()' and 'saverecords()'





void SaveRecords()


{


FILE *fp;


int ctr;


ctr = 0;


fp = fopen("data.dat", "w");


for (ctr = 0; ctr %26lt; count+1; ctr++)


{


fprintf(fp, "%s ", whois[ctr].name);


fprintf(fp, "%s ", whois[ctr].id_no);


fprintf(fp, "%s ", whois[ctr].course);


fprintf(fp, "%s ", whois[ctr].year);


}


fclose(fp);


}





main()


{


int choice, a;


again:


clrscr();


printf("\n Menu:");


printf("\n [1] Load Record");


printf("\n [2] Add");


printf("\n [3] Browse");


printf("\n [4] Change");


printf("\n [5] Delete");


printf("\n [6] Save and Exit");


printf("\n\n choice: ");


choice=getch();


switch(choice)


{


case '1':


showmenu();


break;





case '2':


add();


break;





case '3':


browse();


break;





..etc..





case '6':


SaveRecords();


break;





default:


printf("\n\n\n Invalid Choice!!! Try again...");


getch();


goto again;


}


return 0;


}





I hope you guys could help me out with this.

How to end my program if exit() and _exit() doesn't work? (C Program)?
case '6':


SaveRecords();


if (choose==6) exit; //or goto stop label


break;
Reply:Someone please help me out here. T_T Report It

Reply:if (choice == 6) exit(1); Report It

Reply:ok i've tried this:





if (choice == 6) exit(1);





***but it's still the same. It says "undefined symbol exit".. Report It

Reply:Try end, make sure u unload your forms first.


No comments:

Post a Comment