Trying to fix delete
This commit is contained in:
parent
94ab0d2e10
commit
b12203cd70
3 changed files with 5 additions and 2 deletions
7
lab8/2.c
7
lab8/2.c
|
@ -36,15 +36,18 @@ void delete_entry(FILE * file, unsigned entry_no) {
|
||||||
insert_entry(out, &entry);
|
insert_entry(out, &entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
insert_entry(out, &entry);
|
|
||||||
if ( !found ) {
|
if ( !found ) {
|
||||||
printf("Entry not found!\n");
|
printf("Entry not found!\n");
|
||||||
|
system("rm -f .temp");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
system("rm -f data.bdb; mv .temp data.bdb"); // copy and remove, ty unix <3
|
system("rm -f data.bdb; mv .temp data.bdb"); // copy and remove, ty unix <3
|
||||||
if ( fclose(file) ) {
|
if ( fclose(file) ) {
|
||||||
perror("Can't close file!");
|
perror("Can't close file!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !(file = fopen("data.bdb", "r+b")) ) {
|
if ( !(file = fopen("data.bdb", "r+b")) ) {
|
||||||
perror("Can't open file");
|
perror("Can't open file");
|
||||||
}
|
}
|
||||||
|
@ -116,7 +119,7 @@ void search_entry(FILE * file, long imei) {
|
||||||
Database entry;
|
Database entry;
|
||||||
for( int i = 0; fread(&entry, sizeof(Database), 1, file); i++ ) {
|
for( int i = 0; fread(&entry, sizeof(Database), 1, file); i++ ) {
|
||||||
if ( entry.imei == imei ) {
|
if ( entry.imei == imei ) {
|
||||||
display_entry(&entry, 0);
|
display_entry(&entry, i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
BIN
lab8/data.bdb
BIN
lab8/data.bdb
Binary file not shown.
BIN
lab8/libcipher.a
BIN
lab8/libcipher.a
Binary file not shown.
Loading…
Reference in a new issue