Esato

Forum > General discussions > Non mobile discussion > Need Help In My C Project To Be Passed Tomorrow, bugs pls help

Author Need Help In My C Project To Be Passed Tomorrow, bugs pls help
amnher
Sony Xperia Z1
Joined: Jan 23, 2008
Posts: > 500
From: Taguig,Philippines
PM
Posted: 2009-03-20 10:19
Reply with quoteEdit/Delete This PostPrint this post
Bugs :
1. Problems handling names cause all names scanned includes space at the end(e.g. "Herman Cruz" becomes "Herman Cruz ") making the "View" buggy. Lets say you have 3 records, the view gives me result of 6 records isntead of 3. those extra 3 records have no name. Delte is also bug upon search the name to delete, im forced to include space after the name in order to match the stored name in the data. Same goes for EDIT and search.

2. Cant implement the pause ability in View wherein elts say theres 20 person wherein I can pause for every 3 names then clearscreen.

3. Handle empty records and no search result.
Pls guys I need help. Its my thesis that needs to be defended tomorrow. Its a defense.


#include
void add();
void view();
void edit();
void search();
void dele();
void empty();


void main()
{
int choice;
repeat:
clrscr();
fflush(stdin);
printf("\n\n\n\n\n\n\t\t\t****************************");
printf("\n\t\t\t* Student Grading System *");
printf("\n\t\t\t****************************");
printf("\n\t\t\t* Add [1] *");
printf("\n\t\t\t* View [2] *");
printf("\n\t\t\t* Edit [3] *");
printf("\n\t\t\t* Search [4] *");
printf("\n\t\t\t* Delete [5] *");
printf("\n\t\t\t* Empty Record [6] *");
printf("\n\t\t\t* Exit [0] *");
printf("\n\t\t\t****************************");
printf("\n\t\t\tPlease Enter Your Choice : ");

scanf("%d",&choice);

switch (choice)
{
case 1 :
add();
break;
case 2 :
view();
break;
case 3 :
edit();
break;
case 4 :
search();
break;
case 5 :
dele();
break;
case 6 :
empty();
break;
case 0 :
break;
default:
printf("\n\t\t\tInvalid Choice!!!\n\t\t\tPlease refer to the menu!!!");
getche();
goto repeat;

}

}


void add()
{
char choice,nm[50],name[50];
float sci,math,eng,ave;
FILE *grading;
repeat:
clrscr();


fflush(stdin);
printf("Enter Full Name : ");
scanf("%[^\t\n0-9]",&name);
printf("Enter grade in English : ");
scanf("%f",&eng);
printf("Enter grade in Math : ");
scanf("%f",&math);
printf("Enter grade in Science : ");
scanf("%f",&sci);

ave = (eng+math+sci)/3;
printf("\n-------------------------------\n");
printf("Your average is %.2f",ave);

/* SAVE FILE */
grading=fopen("record.txt","a+");
fprintf(grading,"%s %.2f %.2f %.2f %.2f\n",name,eng,math,sci,ave);
fflush(grading);
fclose(grading);

/*SHOW MESSAGE*/
printf("\n-------------------------------");
printf("\nRecord Added!");
printf("\n-------------------------------");

fflush(stdin);

repeat2:
printf("\n\nDo you want to add another record?\n\n");
printf("[Y] for new a record or [N] to go back to main menu : ");
scanf("%c",&choice);



if((choice=='Y')||(choice=='y')) {
goto repeat;
}
if((choice=='N')||(choice=='n')) {
main();
} else {
clrscr();
printf("\nInvalid choice!!\n");
goto repeat2;
}


}


void view()
{
char name[50];
int ctr=0;
float sci,math,eng,ave;
FILE *grading;
clrscr();
grading=fopen("record.txt","a+");
while(!feof(grading)){
fscanf(grading,"%[^\t\n0-9] %f %f %f %f",&name,&eng,&math,&sci,&ave);
if(feof(grading)){
break;
}
printf("-------------------------------");
printf("\nName : %s\n",name);
printf("English : %.2f\n",eng);
printf("Math : %.2f\n",math);
printf("Science : %.2f\n",sci);
printf("Average : %.2f\n",ave);
ctr++;
if ((ctr>0)&&(ctr<=3)) {
printf("-------------------------------\n");
printf("Press any key to continue...\n");
getche();
}
}
fclose(grading);
printf("\n-------------------------------");
printf("\nPress any key to continue...");
getche();
main();
}


void edit() {
char tempdata[1000],search[50],name[50],nname[50];
float sci,math,eng,ave,nsci,nmath,neng;
int test,test2;
FILE *grading;
FILE *temp;
clrscr();

temp=fopen("temprecord.txt","a+");
grading=fopen("record.txt","r");


printf("Enter the full name : ");
scanf("%[^\t\n0-9]",&search);
do{
fscanf(grading,"%[^\t\n0-9] %f %f %f %f",&name,&eng,&math,&sci,&ave);
test=stricmp(name,search);
if(feof(grading)){
break;
}
if(test!=0) {
fprintf(temp,"%s %f %f %f %f\n",name,eng,math,sci,ave);
}
if(test==0) {
printf("%s has been found\n\n",name);
strcpy(nname,name);
neng=eng;
nmath=math;
nsci=sci;
test2=test;
}
}
while(!feof(grading));
if(test2==0) {
printf("Current Name is %s , Enter New Name : ",nname);
scanf("%[^\t\n0-9]",&name);
printf("Current grade is %.2f, Enter new grade in English : ",neng);
scanf("%f",&eng);
printf("Current grade is %.2f, Enter new grade in Math : ",nmath);
scanf("%f",&math);
printf("Current grade is %.2f, Enter new grade in Science : ",nsci);
scanf("%f",&sci);

ave = (eng+math+sci)/3;
printf("\n-------------------------------\n");
printf("Your average is %.2f",ave);

fprintf(temp,"%s %.2f %.2f %.2f %.2f\n",name,eng,math,sci,ave);
printf("\n-------------------------------");
printf("\nRecord is updated!");
}
if(test2!=0){
printf("\n-------------------------------");
printf("Record not found!!");
}
fclose(temp);
fclose(grading);
remove("record.txt");
rename("tempreco.txt","record.txt");
printf("\n-------------------------------");
printf("\nPress any key to continue...");
getche();
main();

}


void search() {
char choice,s[50],search[50],nm[50],name[50];
float sci,math,eng,ave;
int leng1,leng2,ctr=0;
FILE *grading;
repeat:
clrscr();

fflush(stdin);
grading=fopen("record.txt","r");
printf("Enter the full name : ");

scanf("%[^\t\n0-9]",&search);


while(!feof(grading)){

fscanf(grading,"%[^\t\n0-9] %f %f %f %f",&name,&eng,&math,&sci,&ave);

if(feof(grading)){
break;
}
if(stricmp(search,name)==0){
printf("-------------------------------");
printf("\nName : %s\n",name);
printf("English : %.2f\n",eng);
printf("Math : %.2f\n",math);
printf("Science : %.2f\n",sci);
printf("Average : %.2f\n",ave);
ctr++;
}

}
if(ctr==0) {
printf("-------------------------------\n");
printf("The name doesn't exist!!!");
}
fflush(stdin);
repeat2:
printf("\n-------------------------------");
printf("\nDo you want to search again?\n\n");
printf("[Y] for yes or [N] to go back to main menu: ");
scanf("%c",&choice);
if((choice=='Y')||(choice=='y')) {
goto repeat;
}
if((choice=='N')||(choice=='n')) {
main();
} else {
clrscr();
printf("\nInvalid choice!!\n");
goto repeat2;
}
fclose(grading);

}


void dele()
{
char choice,tempdata[1000],search[50],nname[50],name[50];
float sci,math,eng,ave;
int test,ctr=0;
FILE *grading;
FILE *temp;
repeat:
clrscr();

temp=fopen("temprecord.txt","a+");

grading=fopen("record.txt","a+");
printf("-------------------------------\n");
printf("Name(s) :\n");
printf("-------------------------------\n");
while(!feof(grading)){
fscanf(grading,"%[^\t\n0-9] %f %f %f %f",&nname,&eng,&math,&sci,&ave);
if(feof(grading)){
break;
}

printf("%s\n",nname);
}
printf("\n-------------------------------\n");
fclose(grading);

grading=fopen("record.txt","r");
fflush(stdin);
printf("Enter the full name : ");
scanf("%[^\t\n0-9]",&search);
printf("\n-------------------------------\n");
do{
fscanf(grading,"%[^\t\n0-9] %f %f %f %f",&name,&eng,&math,&sci,&ave);
test=stricmp(name,search);
if(feof(grading)){
break;
}
if(test!=0) {
fprintf(temp,"%s %f %f %f %f\n",name,eng,math,sci,ave);
}
if(test==0) {
printf("%s has been deleted\n",name);
ctr++;
}
}
while(!feof(grading));
if(ctr==0) {
printf("-------------------------------\n");
printf("The name doesn't exist!!!\n");
}
fclose(temp);
fclose(grading);
remove("record.txt");
rename("tempreco.txt","record.txt");
printf("-------------------------------");
fflush(stdin);
repeat2:
printf("\n\nDo you want to delete another record?\n\n");
printf("[Y] for Yes or [N] to go back to main menu: ");
scanf("%c",&choice);
if((choice=='Y')||(choice=='y')) {
goto repeat;
}
if((choice=='N')||(choice=='n')) {
main();
} else {
clrscr();
printf("\nInvalid choice!!\n");
goto repeat2;

}
}

void empty() {
FILE *grading;
clrscr();
printf("-------------------------------\n");
printf("Record Emptied!!");
grading=fopen("record.txt","w+");
fclose(grading);
printf("\n-------------------------------");
printf("\nPress any key to continue...");
getche();
main();


}


Access the forum with a mobile phone via esato.mobi