diff --git a/lcthw-remnants-2/ex17-ec.c b/lcthw-remnants-2/ex17-ec.c index 213bd1c..c11d8ee 100644 --- a/lcthw-remnants-2/ex17-ec.c +++ b/lcthw-remnants-2/ex17-ec.c @@ -13,6 +13,7 @@ struct Address { int set; char name[MAX_DATA]; char email[MAX_DATA]; + char street[MAX_DATA]; }; struct Database { @@ -41,8 +42,8 @@ void die(const char *message, struct Connection *conn) void Address_print(struct Address *addr) { - printf("%d %s %s\n", - addr->id, addr->name, addr->email); + printf("%d %s %s \"%s\"\n", + addr->id, addr->name, addr->email, addr->street); } void Database_load(struct Connection *conn) @@ -106,7 +107,8 @@ void Database_create(struct Connection *conn) } } -void Database_set(struct Connection *conn, int id, const char *name, const char *email) +void Database_set(struct Connection *conn, int id, const char *name, + const char *email, const char *street) { struct Address *addr = &conn->db->rows[id]; if(addr->set) die("Already set, delete it first", conn); @@ -119,6 +121,9 @@ void Database_set(struct Connection *conn, int id, const char *name, const char res = strncpy(addr->email, email, MAX_DATA); if(!res) die("Email copy failed", conn); + + res = strncpy(addr->street, street, MAX_DATA); + if(!res) die("Street copy failed", conn); } void Database_get(struct Connection *conn, int id) @@ -162,7 +167,8 @@ void Database_find(struct Connection *conn, char *search) if(cur->set) { if(strstr(cur->email, search) != NULL || - strstr(cur->name, search) != NULL) { + strstr(cur->name, search) != NULL || + strstr(cur->street, search) != NULL) { Address_print(cur); } } @@ -197,9 +203,9 @@ int main(int argc, char *argv[]) break; case 's': - if(argc != 6) die("Need id, name, email to set", conn); + if(argc != 7) die("Need id, name, email, and street to set", conn); - Database_set(conn, id, argv[4], argv[5]); + Database_set(conn, id, argv[4], argv[5], argv[6]); Database_write(conn); break;