Pridanie logiky na detegovanie priezviska

This commit is contained in:
Tomáš Vlček 2026-03-30 11:39:18 +00:00
parent e9817424cf
commit 11d91a6c0e

View File

@ -29,7 +29,16 @@ int compare(const void* p1, const void* p2)
struct studentApplication *s1 = (struct studentApplication *)p1; struct studentApplication *s1 = (struct studentApplication *)p1;
struct studentApplication *s2 = (struct studentApplication *)p2; 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() int main()
{ {
@ -39,8 +48,8 @@ int main()
int i = 0; int i = 0;
char processedName[BUFFER_SIZE]; char processedName[BUFFER_SIZE];
char processedSurname[BUFFER_SIZE]; char processedSurname[BUFFER_SIZE];
char newLineSymbol = '\n';
char line[BUFFER_SIZE]; char line[BUFFER_SIZE];
memset(line,0, sizeof(line)); memset(line,0, sizeof(line));
setMemoryOfArrays(processedName, processedSurname, student); setMemoryOfArrays(processedName, processedSurname, student);
@ -55,7 +64,6 @@ int main()
{ {
strcpy(student[i].name, processedName); strcpy(student[i].name, processedName);
strcpy(student[i].surname, processedSurname); strcpy(student[i].surname, processedSurname);
strncat(student[i].name, &newLineSymbol, 1);
i++; i++;
} }
} }
@ -68,17 +76,33 @@ int main()
qsort(student, studentsAmount, sizeof(struct studentApplication), compare); qsort(student, studentsAmount, sizeof(struct studentApplication), compare);
// vypis vysledkov: //vykalkuluje realny mozny limit studentov na zaklade nacitanych zaznamov (index premena 'i' = celkovy pocet najdenych studentov)
puts("Prijati studenti:"); //a celkovom pocte akceptovanych studentov najdenom na prvom riadku (studentsAmount premena) a ano, mam zle pomenovane premeny
for (int i = 0; i < studentsAmount; i++)
int limit;
if (i < studentsAmount)
{ {
puts(student[i].name); limit = i;
} }
else
puts("Neprijati studenti:");
for (int i = studentsAmount; student[i].name[0] != '\0'; i++)
{ {
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; return 0;