How to specify the position in txt file to delete record in C programming -


void deleterecord() { file *fp, *fdel; struct person obj; char number[20];  printf("\n============================"); printf("\n            delete"); printf("\n============================\n\n"); fflush(stdin); printf("enter student number delete  :"); scanf("%s", number); fp=fopen("d:\\data.txt","r"); fdel=fopen("d:\\del.txt","w"); while(fscanf(fp,"\n%s\n%s %s\n%s\n%s\n%s\n%s\n%s\n%s\n",              obj.stdnumb, obj.firstname, obj.lastname, obj.icpass,              obj.nationality, obj.gender, obj.dateofbirth,              obj.contact, obj.address)==1)     if(stricmp(number, obj.stdnumb)!=0)         fprintf(fdel, "\n%s\n%s %s\n%s\n%s\n%s\n%s\n%s\n%s\n",                 obj.stdnumb, obj.firstname, obj.lastname, obj.icpass,                 obj.nationality, obj.gender, obj.dateofbirth, obj.contact,                 obj.address); fclose(fp); fclose(fdel); remove("d:\\data.txt"); rename("d:\\del.txt","d:\\data.txt"); printf("successully deleted."); getch(); } 

here full code, removed ; after while, , removed fgetc, if run , delete record, delete record.. it's still not specified.. how fix this?

at first view, "while" ends ";", causes execute nothing, except "while" itself.

all things in intended loop executed always, after evaluation of "while" command!

by way, seems closing files inside loop cause problems on second execution of loop.


Comments

Popular posts from this blog

java - Cast from Object to List<String>: CastClassException -

How to set a border for android Imageview in Longpress? -

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -