diff --git a/cv10/program.c b/cv10/program.c index c18af4a..fcc6775 100644 --- a/cv10/program.c +++ b/cv10/program.c @@ -5,8 +5,8 @@ #define MAX_STUDENTS 100 #define NAME_SIZE 50 -int compare(const void *a, const void *b) { - return strcmp(*(const char **)a, *(const char **)b); +int compareStrings(const void *a, const void *b) { + return strcmp((const char *)a, (const char *)b); } int main() { @@ -23,9 +23,11 @@ int main() { memset(names, 0, sizeof(names)); while (fgets(temp_name, sizeof(temp_name), stdin) != NULL && num_accepted < max_students) { - int i, found = 0; + // // Remove newline character if present + // temp_name[strcspn(temp_name, "\n")] = '\0'; + for (i = 0; i < num_accepted; i++) { if (strcmp(names[i], temp_name) == 0) { found = 1; @@ -40,20 +42,17 @@ int main() { num_students++; } - // Add a null character at the end of the names array - names[num_accepted][0] = '\0'; - - qsort(names, num_accepted, sizeof(names[0]), compare); - if (num_accepted == 0) { printf("Ziadne prihlasky"); } else { + qsort(names, num_accepted, sizeof(names[0]), compareStrings); + printf("Prijati studenti:\n"); for (int i = 0; i < num_accepted; i++) { - printf("%s", names[i]); + printf("%s\n", names[i]); } } - + // if (num_accepted < num_students) { // printf("Neprijati studenti:"); // for (int i = 0; i < max_students; i++) { @@ -64,4 +63,4 @@ int main() { // } return 0; -} \ No newline at end of file +}