Pridanie logiky na detegovanie priezviska
This commit is contained in:
parent
e9817424cf
commit
11d91a6c0e
46
a3/program.c
46
a3/program.c
@ -29,7 +29,16 @@ int compare(const void* p1, const void* p2)
|
||||
struct studentApplication *s1 = (struct studentApplication *)p1;
|
||||
struct studentApplication *s2 = (struct studentApplication *)p2;
|
||||
|
||||
return strcmp(s1->name, s2->name);
|
||||
int result = strcmp(s1->name, s2->name);
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
return strcmp(s1->surname, s2->surname);
|
||||
}
|
||||
else
|
||||
{
|
||||
return strcmp(s1->name, s2->name);
|
||||
}
|
||||
}
|
||||
int main()
|
||||
{
|
||||
@ -39,8 +48,8 @@ int main()
|
||||
int i = 0;
|
||||
char processedName[BUFFER_SIZE];
|
||||
char processedSurname[BUFFER_SIZE];
|
||||
char newLineSymbol = '\n';
|
||||
char line[BUFFER_SIZE];
|
||||
|
||||
memset(line,0, sizeof(line));
|
||||
|
||||
setMemoryOfArrays(processedName, processedSurname, student);
|
||||
@ -55,7 +64,6 @@ int main()
|
||||
{
|
||||
strcpy(student[i].name, processedName);
|
||||
strcpy(student[i].surname, processedSurname);
|
||||
strncat(student[i].name, &newLineSymbol, 1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@ -68,17 +76,33 @@ int main()
|
||||
|
||||
qsort(student, studentsAmount, sizeof(struct studentApplication), compare);
|
||||
|
||||
// vypis vysledkov:
|
||||
puts("Prijati studenti:");
|
||||
for (int i = 0; i < studentsAmount; i++)
|
||||
//vykalkuluje realny mozny limit studentov na zaklade nacitanych zaznamov (index premena 'i' = celkovy pocet najdenych studentov)
|
||||
//a celkovom pocte akceptovanych studentov najdenom na prvom riadku (studentsAmount premena) a ano, mam zle pomenovane premeny
|
||||
|
||||
int limit;
|
||||
if (i < studentsAmount)
|
||||
{
|
||||
puts(student[i].name);
|
||||
limit = i;
|
||||
}
|
||||
|
||||
puts("Neprijati studenti:");
|
||||
for (int i = studentsAmount; student[i].name[0] != '\0'; i++)
|
||||
else
|
||||
{
|
||||
puts(student[i].name);
|
||||
limit = studentsAmount;
|
||||
}
|
||||
|
||||
puts("Prijati studenti:");
|
||||
for (int x = 0; x < limit; x++)
|
||||
{
|
||||
printf("%s %s\n", student[x].name, student[x], surname);
|
||||
}
|
||||
|
||||
//zacne vypisovat zaznamy neprijatych studentov, tam kde prijati koncia... (studentsAmount)
|
||||
if (i > studentsAmount)
|
||||
{
|
||||
puts("Neprijati studenti:");
|
||||
for (int x = studentsAmount; x < i)
|
||||
{
|
||||
printf("%s %s\n", student[x].name, student[x], surname);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user