Initialization
This commit is contained in:
parent
a2e49258b7
commit
ed42221d74
@ -27,7 +27,11 @@ int main() {
|
||||
}
|
||||
|
||||
// Načítanie prihlášok
|
||||
while (scanf("%s", buffer) == 1 && buffer[0] != '\0') {
|
||||
while (num_applications < max_students && fgets(buffer, sizeof(buffer), stdin) != NULL && buffer[0] != '\n') {
|
||||
size_t len = strlen(buffer);
|
||||
if (buffer[len - 1] == '\n') {
|
||||
buffer[len - 1] = '\0'; // odstránenie koncového znaku nového riadku
|
||||
}
|
||||
applications[num_applications] = strdup(buffer);
|
||||
if (applications[num_applications] == NULL) {
|
||||
puts("Chyba alokacie pamate");
|
||||
@ -48,18 +52,10 @@ int main() {
|
||||
// Výpis prijatých študentov
|
||||
puts("Prijati studenti:");
|
||||
int i;
|
||||
for (i = 0; i < num_applications && i < max_students; i++) {
|
||||
for (i = 0; i < num_applications; i++) {
|
||||
printf("%s\n", applications[i]);
|
||||
}
|
||||
|
||||
// Výpis neprijatých študentov
|
||||
if (i < num_applications) {
|
||||
puts("Neprijati studenti:");
|
||||
for (; i < num_applications; i++) {
|
||||
printf("%s\n", applications[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Uvoľnenie pamäte
|
||||
for (i = 0; i < num_applications; i++) {
|
||||
free(applications[i]);
|
||||
|
Loading…
Reference in New Issue
Block a user