Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define M 3
- typedef struct dane
- {
- int ID;
- struct osoba
- {
- char Imie[10];
- char Nazwisko[10];
- }osoba;
- }dane;
- void sort_tab(cons void *d, int mm)
- {
- const dane *t = d;
- int i,j,min_index;
- dane *temp = malloc(sizeof(dane));
- for(i=0; i<mm; i++)
- {
- min_index = i;
- for(j=i+1; j<mm; j++)
- {
- if( strcmp((t+j)->osoba->Imie,(t+min_index)->osoba->Nazwisko) < 0 )
- {
- min_index = j;
- }
- }
- if(min_index != i)
- {
- temp = (t+i);
- (t+i) = (t+min_index);
- (t+min_index) = temp;
- }
- }
- return;
- }
- int main()
- {
- dane tab[M];
- tab[0].ID = 1;
- tab[0].osoba.Imie = "Ania";
- tab[0].osoba.Nazwisko= "Kot";
- tab[1].ID = 2;
- tab[1].osoba.Imie = "Ania";
- tab[1].osoba.Nazwisko= "Pies";
- tab[2].ID = 3;
- tab[2].osoba.Imie = "Ania";
- tab[2].osoba.Nazwisko= "Kruk";
- sort_tab(&tab, M);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement