Pridanie logiky na detegovanie priezviska
This commit is contained in:
parent
e9817424cf
commit
11d91a6c0e
42
a3/program.c
42
a3/program.c
@ -29,8 +29,17 @@ 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;
|
||||||
|
|
||||||
|
int result = strcmp(s1->name, s2->name);
|
||||||
|
|
||||||
|
if (result == 0)
|
||||||
|
{
|
||||||
|
return strcmp(s1->surname, s2->surname);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return strcmp(s1->name, s2->name);
|
return strcmp(s1->name, s2->name);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
//helper/pomocne lokalne premeny
|
//helper/pomocne lokalne premeny
|
||||||
@ -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
|
||||||
|
{
|
||||||
|
limit = studentsAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
puts("Neprijati studenti:");
|
puts("Prijati studenti:");
|
||||||
for (int i = studentsAmount; student[i].name[0] != '\0'; i++)
|
for (int x = 0; x < limit; x++)
|
||||||
{
|
{
|
||||||
puts(student[i].name);
|
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;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user