From 85bc7c538964cf07ecbbeb6e82c04f0ebc8a90c1 Mon Sep 17 00:00:00 2001 From: kr820js Date: Sat, 23 Mar 2024 18:45:12 +0100 Subject: [PATCH] submition4 --- a1/program.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/a1/program.c b/a1/program.c index f35f301..33ed988 100644 --- a/a1/program.c +++ b/a1/program.c @@ -12,7 +12,10 @@ int main() { link* pointer_to_start_of_chain = malloc(sizeof(link)); memset(pointer_to_start_of_chain,0,sizeof(link)); - reading_strings_and_storing_them_in_memory(pointer_to_start_of_chain); + int read_lines = reading_strings_and_storing_them_in_memory(pointer_to_start_of_chain); + if(read_lines==0){ + return 0; + } int result=0; link* next_link = pointer_to_start_of_chain; while(next_link != NULL){ @@ -32,14 +35,15 @@ int main() return 0; } -void reading_strings_and_storing_them_in_memory(link* pointer_to_start_of_chain){ +int reading_strings_and_storing_them_in_memory(link* pointer_to_start_of_chain){ link* next_link = pointer_to_start_of_chain; char buffer[SIZE]; link* ancestor=NULL; + int counter=0; while(1){ if(fgets(buffer, SIZE, stdin)==NULL||buffer[0]=='\n'){ + free(next_link); if(ancestor!=NULL){ - free(ancestor->p_na_next_struct); ancestor->p_na_next_struct=NULL; } break; @@ -53,7 +57,9 @@ void reading_strings_and_storing_them_in_memory(link* pointer_to_start_of_chain) memcpy(next_link->p_na_line, buffer,size); ancestor=next_link; next_link=next_link->p_na_next_struct; + counter++; } + return counter; } int analizing_string(char* pointer){ float number1, number2, result3;