What's wrong with this? - TechRepublic
Question
July 29, 2011 at 12:31 PM
ukitin

What’s wrong with this?

by ukitin . Updated 14 years, 11 months ago

#include
#include
#include
#include

void TITLECRT();
void BORDERDESIGN();
void USERCHOICE();

int BORDER;

int main(void)
{
TITLECRT();
}

void BORDERDESIGN()
{
clrscr();
textcolor(14);
for(BORDER=1;BORDER<=80;BORDER++) { gotoxy(BORDER,1); cprintf("()"); gotoxy(BORDER,24); cprintf("__"); } for(BORDER=2;BORDER<=23;BORDER++) { gotoxy(1,BORDER); cprintf("()"); gotoxy(80,BORDER); cprintf("||"); } } void TITLECRT() { int password1,password; clrscr(); textcolor(14); gotoxy(80,24); cprintf(""); gotoxy(23,4); cprintf("??----------------------------------??"); gotoxy(23,5); cprintf("?? XYZ-Xavier School ??"); gotoxy(23,6); cprintf("?? Student Information System ??"); gotoxy(23,7); cprintf("?? ??"); gotoxy(23,8); cprintf("??----------------------------------??"); gotoxy(23,9); cprintf("()()()()()()()()()()()()()()()()()()"); gotoxy(23,10); cprintf("Press enter to bring up Login page!"); getch(); password1=1234; textcolor(14); gotoxy(30,15); cprintf("Enter password: "); gotoxy(30,31); scanf("%d",&password); if(password==password1) { USERCHOICE(); } else { textcolor(12); gotoxy(29,18); cprintf("Wrong password!!!"); gotoxy(25,23); cprintf("press ENTER to continue ..."); getch(); clrscr(); TITLECRT(); } } void USERCHOICE() { FILE *STUDENTINFOSYSTEM; FILE *STUDENTINFOSYSTEMTEMP1; FILE *STUDENTINFOSYSTEMTEMP2; char YON; char Y='Y'; char STUDFNAME[50],STUDLNAME[50],STUDADDRESS[50],STUDPREVSCHOOL[50],STUDPREVCOURSE[50],STUDPNUM[50],STUDIDNO[50]; char USERSCHOICE,SEARCHQUERY,DELETERECORD; clrscr(); BORDERDESIGN(); textcolor(14); gotoxy(30,12); cprintf("[A]dd Student Record"); gotoxy(30,13); cprintf("[S]earch/Find Student Record"); gotoxy(30,14); cprintf("[D]elete Student Record"); gotoxy(30,15); cprintf("[E]xit Program"); gotoxy(30,17); cprintf("Enter choice: "); scanf("%c",&USERSCHOICE); switch(toupper(USERSCHOICE)){ case 'A': clrscr(); BORDERDESIGN(); STUDENTINFOSYSTEM=fopen("STUDENTINFOSYSTEM.DOC","a"); textcolor(14); gotoxy(22,9); cprintf("Add New Student Record"); gotoxy(22,12); cprintf("First Name : "); gotoxy(22,13); cprintf("Last Name : "); gotoxy(22,14); cprintf("Address : "); gotoxy(22,15); cprintf("Previous School : "); gotoxy(22,16); cprintf("Previous Course : "); gotoxy(22,17); cprintf("Phone Number : "); gotoxy(22,18); cprintf("ID Number : "); gotoxy(23,20); cprintf("Separate words with underscores or hyphens!"); gotoxy(41,12); scanf("%s",STUDFNAME); gotoxy(41,13); scanf("%s",STUDLNAME); gotoxy(41,14); scanf("%s",STUDADDRESS); gotoxy(41,15); scanf("%s",STUDPREVSCHOOL); gotoxy(41,16); scanf("%s",STUDPREVCOURSE); gotoxy(41,17); scanf("%s",STUDPNUM); gotoxy(41,18); scanf("%s",STUDIDNO); gotoxy(26,23); cprintf("Save? ([Y]es or [N]o): "); gotoxy(49,23); scanf("%c",&YON); getch(); do{ switch(toupper(YON)) { case 'Y': gotoxy(37,25); cprintf("Saving data "); fprintf(STUDENTINFOSYSTEM,"%s %s %s %s %s %s\n",STUDFNAME,STUDLNAME,STUDADDRESS,STUDPREVSCHOOL,STUDPREVCOURSE,STUDPNUM); Y='N'; break; case 'N': gotoxy(20,25); cprintf("Saving cancelled"); Y='N'; break; default: gotoxy(20,25); cprintf("No such option ..."); break; } } while(Y=='Y'); gotoxy(20,26); cprintf("Press Enter to Continue..."); fclose(STUDENTINFOSYSTEM); getch(); break; case 'S': clrscr(); BORDERDESIGN(); STUDENTINFOSYSTEM=fopen("STUDENTINFOSYSTEM.doc","r+"); gotoxy(22,6); cprintf("Find Student Record"); gotoxy(22,8); cprintf("First Name : "); gotoxy(41,8); scanf("%s",SEARCHQUERY); fscanf(STUDENTINFOSYSTEM,"%s %s %s %s %s %s\n",STUDFNAME,STUDLNAME,STUDADDRESS,STUDPREVSCHOOL,STUDPREVCOURSE,STUDPNUM); if(stricmp(STUDFNAME,SEARCHQUERY)==0) { gotoxy(30,12); cprintf("Matched STUDENT RECORD!"); gotoxy(32,12); cprintf("%s",STUDFNAME); gotoxy(32,13); cprintf("%s",STUDLNAME); gotoxy(32,14); cprintf("%s",STUDADDRESS); gotoxy(32,15); cprintf("%s",STUDPREVSCHOOL); gotoxy(32,16); cprintf("%s",STUDPREVCOURSE); gotoxy(32,17); cprintf("%s",STUDPNUM); fclose(STUDENTINFOSYSTEM); getch(); } else { gotoxy(41,12); printf("No Record Found ..."); getch(); } fclose(STUDENTINFOSYSTEM); gotoxy(22,19); cprintf("Press to continue..."); getch(); main(); break; case 'D': STUDENTINFOSYSTEM=fopen("STUDENTINFOSYSTEM.doc","r"); clrscr(); BORDERDESIGN(); textcolor(14); gotoxy(20,4); cprintf("Delete Student Record"); gotoxy(16,6); cprintf("Enter First Name : "); gotoxy(16,27); scanf("%s",DELETERECORD); fscanf(STUDENTINFOSYSTEM,"%s %s %s %s %s %s\n",STUDFNAME,STUDLNAME,STUDADDRESS,STUDPREVSCHOOL,STUDPREVCOURSE,STUDPNUM); if(stricmp(STUDFNAME,DELETERECORD)==0) { gotoxy(30,8); cprintf("Matched Student Record"); gotoxy(28,10); cprintf("%s",STUDFNAME); gotoxy(28,11); cprintf("%s",STUDLNAME); gotoxy(28,12); cprintf("%s",STUDADDRESS); gotoxy(28,13); cprintf("%s",STUDPREVSCHOOL); gotoxy(28,14); cprintf("%s",STUDPREVCOURSE); gotoxy(28,15); cprintf("%s",STUDPNUM); getch(); } fclose(STUDENTINFOSYSTEM); gotoxy(22,17); cprintf("Are you sure (y/n)? "); gotoxy(43,17); cprintf("%c",&YON); switch(toupper(YON)) { case 'Y': gotoxy(22,17); cprintf("Deleted Record!"); STUDENTINFOSYSTEM=fopen("STUDENTINFOSYSTEM.DOC","r"); STUDENTINFOSYSTEMTEMP1=fopen("STUDENTINFOSYSTEMTEMP1.DOC","a"); STUDENTINFOSYSTEMTEMP2=fopen("STUDENTINFOSYSTEMTEMP2.DOC","a"); fscanf(STUDENTINFOSYSTEM,"%s %s %s %s %s %s\n",STUDFNAME,STUDLNAME,STUDADDRESS,STUDPREVSCHOOL,STUDPREVCOURSE,STUDPNUM); if(stricmp(DELETERECORD,STUDFNAME)==0) { fprintf(STUDENTINFOSYSTEMTEMP1,"%s %s %s %s %s %s\n",STUDFNAME,STUDLNAME,STUDADDRESS,STUDPREVSCHOOL,STUDPREVCOURSE,STUDPNUM); } else { fprintf(STUDENTINFOSYSTEMTEMP1,"%s %s %s %s %s %s\n",STUDFNAME,STUDLNAME,STUDADDRESS,STUDPREVSCHOOL,STUDPREVCOURSE,STUDPNUM); } fclose(STUDENTINFOSYSTEM); fclose(STUDENTINFOSYSTEMTEMP1); fclose(STUDENTINFOSYSTEMTEMP2); remove("STUDENTINFOSYSTEMTEMP1"); remove("STUDENTINFOSYSTEM"); rename("STUDENTINFOSYSTEMTEMP2","STUDENTINFOSYSTEM"); gotoxy(22,18); cprintf("Press enter to continue..."); getch(); break; case 'N': gotoxy(28,17); cprintf("Cancelled delete record!"); gotoxy(22,18); cprintf("Press enter to continue..."); getch(); break; } break; case 'E': clrscr(); TITLECRT(); BORDERDESIGN(); textcolor(12); gotoxy(30,12); cprintf("Program Teminated"); gotoxy(5,23); cprintf("press ENTER to exit"); getch(); exit(0); break; default: gotoxy(34,21); textcolor(14); cprintf("INVALID OPTION!"); gotoxy(30,23); cprintf("press ENTER to continue ..."); getch(); TITLECRT(); break; } }

This discussion is locked

All Comments