This commit is contained in:
kr820js 2024-03-16 20:50:43 +01:00
parent 0216f95c75
commit 707c06c1bb

View File

@ -10,11 +10,11 @@ struct student {
};
int compar(const void*,const void*);
int loading_the_entire_line_from_standard_input_into_the_helper_field_and_verify_that_i_have_loaded_it_correctly(struct student *databaza,int *size_ptr);
void parce_line_and_save_into_database(char line[],struct student *databaza, int *size_ptr);
int retriving_integer(char *line,char** end);
int parce_line_and_save_into_database(char line[],struct student *databaza, int *size_ptr);
int find_index(struct student databaza[],int size, const char *xxx);
void adding_an_item_to_the_database(struct student databaza[],int *size_ptr, const char* name,int score);
int main()
{
struct student databaza[SIZE];
@ -41,36 +41,30 @@ int loading_the_entire_line_from_standard_input_into_the_helper_field_and_verify
if (r == NULL||strlen(r)==1){
return 0;
}
parce_line_and_save_into_database(line,databaza,size_ptr);
if(parce_line_and_save_into_database(line,databaza,size_ptr)==-1){
return 0;
}
return 1;
}
void parce_line_and_save_into_database(char line[],struct student *databaza, int *size_ptr){
int parce_line_and_save_into_database(char line[],struct student *databaza, int *size_ptr){
char* end = NULL;
int score=retriving_integer(line,&end);
int score=strtol(line,&end,10);
if(score==0){
return;
return -1;
}
char name[SIZE];
memset(name,0,SIZE);
end += 1;
int velkost_mena = strlen(end) - 1;
if (velkost_mena > 0){
memcpy(name,end,velkost_mena);
}
else {
return;
if (velkost_mena == 0){
return -1;
}
memcpy(name,end,velkost_mena);
adding_an_item_to_the_database( databaza, size_ptr, name, score);
}
int retriving_integer(char *line,char** end){
int value = strtol(line,end,10);
if (value == 0){
return 0;
}
return value;
}
int find_index(struct student databaza[],int size, const char *xxx){
for(int i=0; i<size; i++){
if(strcmp(databaza[i].name,xxx)==0){
@ -97,11 +91,10 @@ int compar(const void* a,const void* b){
if(a_ptr->score < b_ptr->score) {
return 1;
}
if(a_ptr->score > b_ptr->score) {
if(b_ptr->score > a_ptr->score) {
return -1;
}
if(a_ptr->score == b_ptr->score){
return strcmp(a_ptr->name, b_ptr->name);
}
return strcmp(a_ptr->name, b_ptr->name);
}