Fixing some errors
This commit is contained in:
parent
9c39315d0b
commit
9cc5cb0bf8
2 changed files with 12 additions and 8 deletions
20
lab8/2.c
20
lab8/2.c
|
@ -30,7 +30,7 @@ void delete_entry(FILE * file, unsigned entry_no) {
|
|||
Database entry;
|
||||
short found = 0;
|
||||
FILE * out;
|
||||
if ( (out = fopen(".temp", "wb")) ) {
|
||||
if ( !(out = fopen(".temp", "wb")) ) {
|
||||
perror("Error opening file!");
|
||||
exit(0);
|
||||
}
|
||||
|
@ -106,20 +106,24 @@ void update_entry(FILE * file, unsigned entry_no) {
|
|||
void blacklist_entry(FILE * file, unsigned entry_no) {
|
||||
fseek(file, 0, SEEK_SET);
|
||||
Database entry;
|
||||
// long imei = 0;
|
||||
for( int i = 0; fread(&entry, sizeof(Database), 1, file); i++ ) {
|
||||
if ( i == entry_no ) {
|
||||
printf("Entry found!\n");
|
||||
fseek(file, -sizeof(Database), SEEK_CUR);
|
||||
if (entry.blacklisted) {
|
||||
printf("Entry has been Unblacklisted!\n");
|
||||
entry.blacklisted = 0;
|
||||
} else {
|
||||
printf("Entry has been Blacklisted!\n");
|
||||
entry.blacklisted = 1;
|
||||
}
|
||||
// imei = entry.imei;
|
||||
entry.blacklisted ^= 1;
|
||||
fwrite(&entry, sizeof(Database), 1, file);
|
||||
}
|
||||
}
|
||||
// fseek(file, 0, SEEK_SET);
|
||||
// for( int i = 0; fread(&entry, sizeof(Database), 1, file); i++ ) {
|
||||
// if ( entry.imei == imei) {
|
||||
// fseek(file, -sizeof(Database), SEEK_CUR);
|
||||
// entry.blacklisted ^= 1;
|
||||
// fwrite(&entry, sizeof(Database), 1, file);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
void search_entry(FILE * file, long imei) {
|
||||
|
|
BIN
lab8/data.bdb
BIN
lab8/data.bdb
Binary file not shown.
Loading…
Reference in a new issue