fork download
  1. #include<stdio.h>
  2. #include <string.h>
  3.  
  4. //for using tolower
  5. #include <ctype.h>
  6. int main() {
  7. int i, k, j, n=0;
  8. char abc[25];
  9. const char *stop = "stop";
  10. char *p; //using for lowercase
  11. //using 2d array for max of 10,000 words, max size of words 25
  12. char str[10000][25], temp[25];
  13.  
  14. printf("Enter up to 10000 words, type stop to enter the current words:\n");
  15. while (scanf("%24s", abc)>0 && strncmp(abc, "stop", 5) != 0) {
  16. strncpy (str[n++], abc, 25);
  17. }
  18. //printf("YES\n");
  19. //return (1);
  20.  
  21. for (i = 0; i < n; ++i)
  22. for (k = i + 1; k < n; ++k) {
  23. //comparing two strings using strcmp() function is used
  24. //using strcpy() to copy string to a temp
  25. if (strcmp(str[i], str[k]) > 0) {
  26. strcpy(temp, str[i]);
  27. strcpy(str[i], str[k]);
  28. strcpy(str[k], temp);
  29. }
  30. }
  31.  
  32. //using pointer to converting to lowercase
  33. //src: https://w...content-available-to-author-only...b.com/programming/software-development/threads/57296/how-does-one-tolower-an-entire-string
  34. for (i =0; i<n; i++)
  35. for (p = str[i]; *p != '\0'; p++)
  36. *p = (char) tolower(*p);
  37.  
  38. //printing words in lexi order
  39. printf("\nWords in lexicographical order: \n");
  40. for (i = 0; i < n; ++i) {
  41. puts(str[i]);
  42. }
  43. printf("WARNING: Words longer than 25 in length were ignored. \n");
  44.  
  45. return 0;
  46.  
  47. }
Success #stdin #stdout 0s 3596KB
stdin
hello stop
stdout
Enter up to 10000 words, type stop to enter the current words:

Words in lexicographical order: 
hello
WARNING: Words longer than 25 in length were ignored.