fork(1) download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #define Lim 1000
  5.  
  6. int main()
  7. {
  8. int idx = 0, i, j;
  9. char str[Lim], *lines[Lim], temp[Lim];
  10. while (fgets (str, Lim, stdin) != NULL)
  11. {
  12. lines[idx] = strdup(str);
  13. printf ("%s",lines[idx]);
  14. idx++;
  15. }
  16. for (i = 0; i < Lim; i++)
  17. {
  18. for (j = 0; j < idx; j++)
  19. {
  20. if ((strcmp(lines[j], lines[j+1])) > 0)
  21. {
  22. strcpy (temp, lines[j]);
  23. strcpy (lines[j], lines[j+1]);
  24. strcpy (lines[j+1], temp);
  25. }
  26. }
  27. }
  28.  
  29. for (j = 0; j < idx; j++)
  30. {
  31. printf("%s",lines[j]);
  32. }
  33.  
  34. return 0;
  35. }
  36.  
  37.  
Runtime error #stdin #stdout 0s 2296KB
stdin
apple
banana
candy
cat
stdout
Standard output is empty