Skip to content

Instantly share code, notes, and snippets.

@DannyFeliz
Last active May 22, 2016 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DannyFeliz/b397a82c1463c8fdc30cff86e783bd36 to your computer and use it in GitHub Desktop.
Save DannyFeliz/b397a82c1463c8fdc30cff86e783bd36 to your computer and use it in GitHub Desktop.
Soft array alphabetically
#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