From 6e3696f4b1ca4f6fb4e3e276afdd8622052a8e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nut=CC=A6iu?= Date: Fri, 15 Apr 2016 12:59:26 +0300 Subject: [PATCH] Updating search function --- lab8/2.c | 13 ++++++++++--- lab8/data.bdb | Bin 480 -> 320 bytes lab8/libcipher.a | Bin 1416 -> 1416 bytes 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lab8/2.c b/lab8/2.c index 3435f7e..36b6a1b 100644 --- a/lab8/2.c +++ b/lab8/2.c @@ -18,6 +18,8 @@ void display_entry(Database * entry, unsigned index); void insert_entry(FILE * file, Database * entry); void read_entry(FILE * file, Database * entry); void validate_input(int i); +void display_header(); +void display_menu(); // Deletes entry by making a temporary file and copying everything in it. // Except for the deleted entry, after that it deletes the original file @@ -43,11 +45,12 @@ void delete_entry(FILE * file, unsigned entry_no) { return; } - system("rm -f data.bdb; mv .temp data.bdb"); // copy and remove, ty unix <3 if ( fclose(file) || fclose(out) ) { perror("Can't close file!"); } + system("rm -f data.bdb; mv .temp data.bdb"); // copy and remove, ty unix <3 + if ( !(file = fopen("data.bdb", "r+b")) ) { perror("Can't open file"); } @@ -117,13 +120,17 @@ void blacklist_entry(FILE * file, unsigned entry_no) { void search_entry(FILE * file, long imei) { fseek(file, 0, SEEK_SET); Database entry; + short found = 0; for( int i = 0; fread(&entry, sizeof(Database), 1, file); i++ ) { if ( entry.imei == imei ) { + if (!found) display_header(); display_entry(&entry, i); - return; + found = 1; } } - printf("Entry not found!\n"); + if ( !found ) { + printf("Entry not found!\n"); + } } void insert_entry(FILE * file, Database * entry) { diff --git a/lab8/data.bdb b/lab8/data.bdb index e2cbd8934be14d53d3d850147f092f285072c8e4..38e337ba94820fdaa93e005a64d79af4fb59faba 100644 GIT binary patch delta 105 zcmaFBe1K_!gX9SY28L-sYy`w0z~qx(mda3^$S{#pU+^1;23SxXNb&=*#Kf85A`DK6 pC8+`i(<_!5qlk z52QhW$vLqoIk7mAfkg8}&qlL@^veM;7Z8hpI6%PUm!F-Ps1TG|mY7=r5ketxx$l+O z1|KG%N|2Ylfmjl%Yk?6%EXe(Jiy{69fQrLtkY7RIz?8*cbue*|Ss(zSVQi2&0>;Fd mXMkoNGuSi+1`rKngUkysgGj*ag}H~2em1CiAR5L7nFj#r%25#j diff --git a/lab8/libcipher.a b/lab8/libcipher.a index 7601d8e724082ad3edd4142c72b63a6e0f7bb7d4..595559a524ad00c25b54f9844dad2327c202b52c 100644 GIT binary patch delta 25 dcmeC+?%5$uyNNp764Z12V4LE delta 25 ecmeC+?%