|
Answer» Hi I am currently writing a program in C that is like an arithmetic system for kids. The teacher user can add,modify,delete questions from the question bank.so i have writen functions for all of these but the thing is whenever I GET to the delete function it stops running after asking the user the questions they want to delete. Like I press enter and then try one more time but it just gets stuck there no message or anything just stuck.I PERSONALLY think there is something wrong with the file openind and closing. Below is the function, can ANYBODY pls help me and see what's wrong.
void delexpr(void){ FILE *fp; int qno,i=0; struct question buffer;
clrscr(); fflush(stdin); printf("\n"); printf("%sDeleting an Arithmetic Expression from the Question Bank\n",INDENT); printf("%s^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",INDENT); printf("\n"); showexpr(); printf("\n"); fp = fopen("question.dat", "rb"); if (fp==NULL){ printf("File Error!\n"); } else{ printf("Please enter the number of the expression that you want to delete:"); scanf("%d\n", &qno);
for(i=0;i<numq;i++){ while(i!=qno){ buffer=bank; } } }fclose(fp); fp = fopen("question.dat", "wb"); //open the binary file q.dat for updating if (fp==NULL){ printf("File Error!\n"); } else { for(i=0;i<numq;i++){ fwrite(&buffer,sizeof(struct question),1,fp); fclose(fp); } } TAB4; showexpr(); TAB4; printf("Expression Deleted!\n");
printf("\n"); }
bank is the array for the question bank and so is buffer but it is only a temporary one and showexpr() is another function that displays all the questions. Pls see if anyone can help me...I was thinking that maybe you are missing a #include for the fstream, but if it compiles it cant be that. Also looked at your bracers and all and I dont see any problem. Maybe someone else will point out what we are both missing here.
|