Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct local{
- char *name;
- struct local *next;
- }t_local;
- void printlocalsalphabetical(t_local *header_l){
- createlistlocals(*header_l);
- sort_alphabetical(*header_l);
- t_local l = header_l->next;
- while (l){
- puts(l->name);
- l=l->next;
- }
- }
- void crialistlocals(t_local *header_l){
- FILE *fp;
- t_local *aux = header_l->next;
- char line[150];
- char *namel;
- fp = fopen("locais.txt","r");
- while (!feof(fp)){
- fgets(line, 100, fp);
- namel = strtok(line, '/');
- aux->name = namel;
- aux->next = header_l;
- header_l= aux;
- }
- }
- void sort_alphabetical(t_local *header_l){
- int swapped;
- t_local *ptr1;
- t_local *lptr = NULL;
- if (header_l == NULL)
- return;
- do
- {
- swapped = 0;
- ptr1 = header_l;
- while (ptr1->next != lptr)
- {
- if (ptr1->name > ptr1->prox->name)
- {
- swap(ptr1, ptr1->next);
- swapped = 1;
- }
- ptr1 = ptr1->next;
- }
- lptr = ptr1;
- }
- while (swapped);
- }
- void swap(t_local *a, t_local *b)
- {
- char *temp = a->name;
- a->name = b->name;
- b->name = strdup(temp);
- }
- t_local *create_headerL(void){
- t_local *list = (t_local*)malloc(sizeof(t_local));
- if (list != NULL)
- list->next = NULL;
- return lista;
- }
- int main()
- {
- t_local *header_l = create_headerL();
- printlocalsalphabetical(*header_l);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement