From 2ba8bd9d57db08237f419bca71a917e986e46dbc Mon Sep 17 00:00:00 2001 From: Numillyash Date: Thu, 6 Oct 2022 17:36:44 +0300 Subject: [PATCH] updateFunc --- Varya_Struct_02/Varya_Struct_02.c | 4 +++- Varya_Struct_02/db_struct.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Varya_Struct_02/Varya_Struct_02.c b/Varya_Struct_02/Varya_Struct_02.c index e5cf803..79a09ed 100644 --- a/Varya_Struct_02/Varya_Struct_02.c +++ b/Varya_Struct_02/Varya_Struct_02.c @@ -28,11 +28,13 @@ int main() printf("uniq:%d \n", deleteNonUniqElements()); - char selects[7] = { 1, 5, 3, -1, -1, -1, -1 }; + char selects[7] = { 0, 5, 3, -1, -1, -1, -1 }; Condition a = { moreEqual, 2, 0, NULL, 0, NULL }; Condition* conditions[7] = {NULL, NULL, NULL, &a, NULL, NULL, NULL}; printf("\nselect:%d \n", selectFunc(selects, conditions)); + printf("\nupdate:%d \n", updateFunc("TeStNaMe", NULL, -1, -1, NULL, NULL, NULL, conditions)); + printf("\nselect:%d \n", selectFunc(selects, conditions)); //printDataBase(); diff --git a/Varya_Struct_02/db_struct.h b/Varya_Struct_02/db_struct.h index 4a88fa0..0def3ad 100644 --- a/Varya_Struct_02/db_struct.h +++ b/Varya_Struct_02/db_struct.h @@ -485,3 +485,33 @@ int selectFunc(char whatToPrint[7], Condition* conditions[7]) } return count; } + +int updateFunc(char* lastName, char* firstName, int course, int labID, time_t* startTime, time_t* endTime, int results[99],Condition* conditions[7]) +{ + int count = 0; + DataBaseElement* tmp; + tmp = head; + while (tmp != NULL) + { + if (isElementRespondConditions(tmp, conditions)) + { + if (lastName != NULL) + tmp->last_nm = lastName; + if (firstName != NULL) + tmp->first_nm = firstName; + if (course != -1) + tmp->curse_id = course; + if (labID != -1) + tmp->lab_id = labID; + if (startTime != NULL) + tmp->start_tm = startTime; + if (endTime != NULL) + tmp->end_tm = endTime; + if (results != NULL) + tmp->result = results; + count++; + } + tmp = tmp->nextElement; + } + return count; +} \ No newline at end of file