Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define ARR 5
- void sort(char string[][64], int n);
- int main()
- {
- char string[ARR][64]; int i;
- strcpy(string[0], "Judas Priest");
- strcpy(string[1], "Dark Tranquillity");
- strcpy(string[2], "Iron Maiden");
- strcpy(string[3], "Black Sabbath");
- strcpy(string[4], "Dio");
- sort(string, ARR);
- for (i=0; i < ARR; i++)
- {
- printf("%s\n", string[i]);
- }
- return 0;
- }
- void sort(char string[][64], int n)
- {
- int i, j;
- char tmp[64];
- int change = 1;
- for (i=0; i<n-1 && change; ++i)
- {
- change = 0;
- for (j=0; j < n-1-i; ++j)
- {
- if (strcmp(string[j+1], string[j]) < 0)
- {
- strcpy(tmp, string[j]);
- strcpy(string[j], string[j+1]);
- strcpy(string[j+1], tmp);
- change = 1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement