Last active
May 22, 2016 02:12
-
-
Save DannyFeliz/b397a82c1463c8fdc30cff86e783bd36 to your computer and use it in GitHub Desktop.
Soft array alphabetically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
int main(void) { | |
char *names[] = {"Danny", "Florida", "Oregon", "Gaby", "Califoria", "Georgia", "Octavio", "Ana"}; | |
int namesLength = (int)( sizeof(names) / sizeof(names[0]) ); | |
for (int i = 0; i < namesLength; i++) { | |
for (int j = i+1; j < namesLength; j++) { | |
if (strcmp(names[i], names[j]) > 0) { | |
char* temp = names[i]; | |
names[i] = names[j]; | |
names[j] = temp; | |
} | |
} | |
// Gabi, now you need to use a linked list or something like that to append the result | |
printf("%s ", names[i]); | |
} | |
getchar(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment