fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define NUM (sizeof(Strings)/sizeof(*Strings))
  5.  
  6. int main(void) {
  7. char Strings[][32] = {
  8. "Red", "Green", "Blue", "Brown", "Yellow"
  9. };
  10. char temp[sizeof *Strings];
  11.  
  12. for(int i = 0; i < NUM -1; i++){
  13. for(int j = 0; j < NUM- 1 -i; j++){
  14. if (strcmp(Strings[j], Strings[j+1]) > 0){
  15. strcpy(temp, Strings[j]);
  16. strcpy(Strings[j], Strings[j+1]);
  17. strcpy(Strings[j+1], temp);
  18. }
  19. }
  20. }
  21. for(int i = 0; i < NUM; ++i){
  22. printf("%s\n", Strings[i]);
  23. }
  24. }
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
Blue
Brown
Green
Red
Yellow