Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define SIZE 16
- #define N 5
- struct Prova
- {
- char nome[SIZE];
- };
- void sort(struct Prova *ptr)
- {
- char temp[SIZE];
- for(int i = 0; i < N; i++)
- {
- for(int j = i+1; j < N; j++)
- {
- if(strcmp((ptr+i)->nome,(ptr+j)->nome) < 0)
- {
- strcpy(temp, (ptr+i)->nome);
- strcpy((ptr+i)->nome,(ptr+j)->nome);
- strcpy(temp, (ptr+j)->nome);
- }
- }
- }
- }
- int main()
- {
- struct Prova * ptr;
- ptr = (struct Prova*)malloc(N * sizeof(struct Prova));
- for(int i = 0; i< N; i++)
- {
- scanf(" %s", (ptr+i)->nome);
- }
- sort(ptr);
- for(int i = 0; i< N; i++)
- {
- printf("%sn", (ptr+i)->nome);
- }
- }
Add Comment
Please, Sign In to add comment