Aktualizovat a3/program.c
This commit is contained in:
parent
1a9506f747
commit
0fd31a3c2e
34
a3/program.c
34
a3/program.c
@ -1,21 +1,24 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#DEFINE BUFFER_SIZE 64;
|
#DEFINE BUFFER_SIZE 64;
|
||||||
#DEFINE STUDENT_SIZE 32;
|
#DEFINE STUDENT_SIZE 32;
|
||||||
|
|
||||||
struct studentApplication
|
struct studentApplication
|
||||||
{
|
{
|
||||||
char meno[BUFFER_SIZE];
|
char name[STUDENT_SIZE];
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
//helper/pomocne lokalne premeny
|
||||||
int studentsAmount;
|
int studentsAmount;
|
||||||
struct studentsApplication student[STUDENT_SIZE];
|
struct studentsApplication student[STUDENT_SIZE];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char processedName[BUFFER_SIZE];
|
char processedName[BUFFER_SIZE];
|
||||||
|
char newLineSymbol = '\n';
|
||||||
|
|
||||||
setMemoryOfArrays(processedName, student);
|
setMemoryOfArrays(processedName, student);
|
||||||
|
|
||||||
@ -28,6 +31,7 @@ int main()
|
|||||||
else if(sscanf(line, "%s", processedName) == 1)
|
else if(sscanf(line, "%s", processedName) == 1)
|
||||||
{
|
{
|
||||||
strcpy(student[i].meno, processedName);
|
strcpy(student[i].meno, processedName);
|
||||||
|
strncat(student[i].meno, &newLineSymbol, 1);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -38,6 +42,21 @@ int main()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qsort(student, STUDENT_SIZE, sizeof(struct studentsApplication), compare);
|
||||||
|
|
||||||
|
// vypis vysledkov:
|
||||||
|
for (int i = 0; i < studentsAmount; i++)
|
||||||
|
{
|
||||||
|
puts("Prijati studenti:");
|
||||||
|
puts(student[i].meno);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; student[i].meno[0] != '\0'; i++)
|
||||||
|
{
|
||||||
|
puts("Neprijati studenti:");
|
||||||
|
puts(student[i].meno);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -46,9 +65,18 @@ void setMemoryOfArrays(char* processedName, studentsApplication* student)
|
|||||||
//prednastavi pamat mnozinovych premien
|
//prednastavi pamat mnozinovych premien
|
||||||
processedName[0] = '\0';
|
processedName[0] = '\0';
|
||||||
|
|
||||||
for (int i = 0; i++; i < STUDENT_SIZE)
|
for (int i = 0; i < STUDENT_SIZE; i++)
|
||||||
{
|
{
|
||||||
student[i].meno = '\0';
|
student[i].meno[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
int compare(const void* p1, const void* p2)
|
||||||
|
{
|
||||||
|
//casting, resp. premena dat. typu pointerov na ich spravny typ
|
||||||
|
//nakolko qsort() pozaduje od porovnavaciej funkcie, aby akceptovala pointery s lubovolnym dat. typom (const void*)
|
||||||
|
struct studentsApplication *s1 = (struct studentsApplication *)p1;
|
||||||
|
struct studentsApplication *s2 = (struct studentsApplication *)p2;
|
||||||
|
|
||||||
|
return strcmp(s1->name, s2->name);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user