diff --git a/lab8/2.c b/lab8/2.c index f27da52..61c75db 100644 --- a/lab8/2.c +++ b/lab8/2.c @@ -36,15 +36,18 @@ void delete_entry(FILE * file, unsigned entry_no) { insert_entry(out, &entry); } } - insert_entry(out, &entry); + if ( !found ) { 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 if ( fclose(file) ) { perror("Can't close file!"); } + if ( !(file = fopen("data.bdb", "r+b")) ) { perror("Can't open file"); } @@ -116,7 +119,7 @@ void search_entry(FILE * file, long imei) { Database entry; for( int i = 0; fread(&entry, sizeof(Database), 1, file); i++ ) { if ( entry.imei == imei ) { - display_entry(&entry, 0); + display_entry(&entry, i); return; } } diff --git a/lab8/data.bdb b/lab8/data.bdb index 81d93c6..b06ee00 100644 Binary files a/lab8/data.bdb and b/lab8/data.bdb differ diff --git a/lab8/libcipher.a b/lab8/libcipher.a index 73a7cd6..eb54f4d 100644 Binary files a/lab8/libcipher.a and b/lab8/libcipher.a differ