Загрузил(а) файлы в 'du6'
This commit is contained in:
parent
2a26acc01f
commit
33caa1cbbd
BIN
du6/program
Normal file
BIN
du6/program
Normal file
Binary file not shown.
93
du6/program.c
Normal file
93
du6/program.c
Normal file
@ -0,0 +1,93 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define ROZMER 100
|
||||
int compare(const void* a1, const void* a2){//na triedenie poľa
|
||||
char* string1 = *((char**)a1);
|
||||
char* string2 = *((char**)a2);
|
||||
int r = strcmp(string1,string2);
|
||||
return r;
|
||||
}
|
||||
|
||||
int printStatus(int pocet_mien_v_poli,int number_list){
|
||||
if (number_list < 0 || number_list == 0)
|
||||
{
|
||||
printf("Nespravny vstup\n");
|
||||
return 0;
|
||||
}
|
||||
if (pocet_mien_v_poli==1)
|
||||
{
|
||||
printf("Ziadne prihlasky\n");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
void printAllStudents(int pocet_mien_v_poli, int number_list, char* pole_smernikov[ROZMER]){
|
||||
for (size_t i = 0; i <=number_list ; i++)
|
||||
{
|
||||
if (pole_smernikov[i]!=NULL)
|
||||
{
|
||||
printf("%s",pole_smernikov[i]);
|
||||
}
|
||||
}
|
||||
if (number_list+1 < pocet_mien_v_poli)
|
||||
{
|
||||
printf("Neprijati studenti:\n");
|
||||
}
|
||||
for (size_t i = number_list+1; i < pocet_mien_v_poli ; i++)
|
||||
{
|
||||
if (pole_smernikov[i]!=NULL)
|
||||
{
|
||||
printf("%s",pole_smernikov[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
int pocet_mien_v_poli = 0;
|
||||
int number_list = 0;
|
||||
char* pole_smernikov[ROZMER];
|
||||
memset(pole_smernikov,0,ROZMER*sizeof(char*));
|
||||
scanf("%d", &number_list);
|
||||
|
||||
// prečítať všetkých študentov z terminálu
|
||||
while (true)
|
||||
{
|
||||
char line[ROZMER];
|
||||
memset(line,0,ROZMER);
|
||||
char* r = fgets(line,ROZMER,stdin);
|
||||
int pocet_znakov = 0;
|
||||
if (r!=NULL){
|
||||
pocet_znakov = strlen(line);
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
bool find = false;
|
||||
for (int i = 0; i < pocet_mien_v_poli; i++){
|
||||
if (memcmp(pole_smernikov[i],line,pocet_znakov) == 0){
|
||||
find = true;
|
||||
}
|
||||
}
|
||||
if(find == false){
|
||||
pole_smernikov[pocet_mien_v_poli] = calloc(' ',pocet_znakov + 1);
|
||||
memcpy(pole_smernikov[pocet_mien_v_poli],line,pocet_znakov + 1);
|
||||
pocet_mien_v_poli ++;
|
||||
}
|
||||
find = false;
|
||||
}
|
||||
|
||||
if (printStatus(pocet_mien_v_poli, number_list) == 0){
|
||||
return 0;
|
||||
}
|
||||
|
||||
qsort(pole_smernikov,pocet_mien_v_poli,sizeof(char*),compare);//triedi pole pomocou komparátora
|
||||
|
||||
printf("Prijati studenti:");
|
||||
printAllStudents(pocet_mien_v_poli,number_list,pole_smernikov);
|
||||
|
||||
for (int i = 0; i < pocet_mien_v_poli; i++){
|
||||
free(pole_smernikov[i]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user