thurmag@jacobs.cs.orst.edu (Gary Thurman) (05/02/91)
I have a question on using fwrite() to delete information from a database. I have gotten help here before, and appreciate any info you can send my way. If it will ease the situation, THIS IS NOT A HOMEWORK ASSIGNMENT! I am not going to school. Even though after some of you look at this, you'll probably say I should! :-) i am trying to use the fwrite() function to remove information from a database. Can you "re-write" over the top of a sector stored in the database by fwriting over the top of it? Below is what I have come up with, but the information I wish to delete is still remains in the database. Again, thanks for any help you can send my way. I have found that the subject of deleting information from a database, is hard to come by in text books. I have defined in the structure addr, char delete; /* remove a name from the list */ void delete() { FILE *fptr; char name[40]; struct addr addr_info; if((fptr=fopen("maillist.dbf","rb"))==NULL) { fprintf(stderr,"Can't open, name not found.\n"); return; } printf("\n\n\n\n\n\n\t\t\tName your looking for? "); gets(name); while(!feof(fptr)) { fread(&addr_info,sizeof(struct addr),1,fptr); if(!strcmp(addr_info.name, name)) { printf("\n\n\n\n\n\n\t\t\t\t%s\n", &addr_info.name); printf("\t\t\t\t%s\n", &addr_info.street); printf("\t\t\t\t%s\n", &addr_info.city); printf("\t\t\t\t%s\n", &addr_info.state); printf("\t\t\t\t%s\n", &addr_info.zip); printf("\n\t\tIs this the name you want to remove? (Type 'y' or 'n'): "); while(getche() == 'y'); addr_info.delete='y'; fwrite(&addr_info,sizeof(struct addr),1,fptr); clrscr(); return; } } fclose(fptr); } -- _**_ "We came...We saw...We kicked some ASH!" /____|-IIIIIIIIIIII Gary Thurman ------ FIREFIGHTER/EMT 2 >| 132 |-----------\ Email: thurmag@jacobs.cs.orst.edu +-(O)--------(O)--+ Corvallis, Oregon