Aktualizovat a3/program.c

This commit is contained in:
Tomáš Vlček 2026-03-30 11:03:10 +00:00
parent 8af04d02e4
commit 0e6bf56c36

View File

@ -9,8 +9,9 @@
struct studentApplication
{
char name[STUDENT_SIZE];
char surname[STUDENT_SIZE];
};
void setMemoryOfArrays(char* processedName, struct studentApplication* student)
void setMemoryOfArrays(char* processedName, char* processedSurname, struct studentApplication* student)
{
//prednastavi pamat mnozinovych premien
processedName[0] = '\0';
@ -37,11 +38,12 @@ int main()
struct studentApplication student[STUDENT_SIZE];
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, student);
setMemoryOfArrays(processedName, processedSurname, student);
while (fgets(line, BUFFER_SIZE, stdin) != NULL)
{
@ -49,7 +51,7 @@ int main()
{
if(sscanf(line, "%d", &studentsAmount) == 1) { continue; }
}
else if(sscanf(line, "%s", processedName) == 1)
else if(sscanf(line, "%s %s", processedName, processedSurname) == 2)
{
strcpy(student[i].name, processedName);
strncat(student[i].name, &newLineSymbol, 1);
@ -62,8 +64,8 @@ int main()
puts("Nespravny vstup");
return 0;
}
qsort(student, STUDENT_SIZE, sizeof(struct studentApplication), compare);
qsort(student, studentsAmount, sizeof(struct studentApplication), compare);
// vypis vysledkov:
puts("Prijati studenti:");