fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define SIZE 100
  5.  
  6. int main(void)
  7. {
  8. char string1[SIZE];
  9. char string2[SIZE];
  10.  
  11. printf("Enter the first string: ");
  12. fgets(string1, SIZE, stdin);
  13.  
  14. printf("Enter the second string: ");
  15. fgets(string2, SIZE, stdin);
  16.  
  17. string1[strcspn(string1, "\n")] = '\0';
  18. string2[strcspn(string2, "\n")] = '\0';
  19.  
  20. int result = strcmp(string1, string2);
  21.  
  22. if (result < 0)
  23. {
  24. printf("The first string is less than the second string.\n");
  25. }
  26. else if (result > 0)
  27. {
  28. printf("The first string is greater than the second string.\n");
  29. }
  30. else
  31. {
  32. printf("The two strings are equal.\n");
  33. }
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0s 5352KB
stdin
Standard input is empty
stdout
Enter the first string: Enter the second string: The first string is greater than the second string.