Niloy007

Eashrat's Problem

Sep 12th, 2020
1,061
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main() {
  4.     char str[100];
  5.     char str2[100];
  6.     gets(str);
  7.     gets(str2);
  8.     int i = 0;
  9.     int flagSTR = 0, flagSTR2 = 0;
  10.     while (str[i] != '\0' && str2[i] != '\0') {
  11.         if (str[i] < str2[i]) {
  12.             //printf("str2 smaller than str\n");//
  13.             // printf("%s\n", str);
  14.             flagSTR = 1;
  15.             break;
  16.         } else if (str[i] > str2[i]) {
  17.             // printf("str smaller than str2\n");//
  18.             // printf("%s\n", str2);
  19.             flagSTR2 = 1;
  20.             break;
  21.         }
  22.         i++;
  23.     }
  24.  
  25.     int len1 = strlen(str);
  26.     int len2 = strlen(str2);
  27.  
  28.     if (flagSTR == 0 && flagSTR2 == 0 && len1 == len2) {
  29.         printf("str & str2 equal\n");
  30.     } else if(flagSTR == 0 && flagSTR2 == 0 && len1 < len2) {
  31.         printf("%s\n", str);
  32.         printf("str smaller than str2\n");
  33.     } else if(flagSTR == 0 && flagSTR2 == 0 && len2 < len1) {
  34.         printf("%s\n", str);
  35.         printf("str2 smaller than str\n");
  36.     } else if (flagSTR == 1 && flagSTR2 == 0) {
  37.         printf("%s\n", str);
  38.         printf("str smaller than str2\n");
  39.     } else if (flagSTR2 == 1 && flagSTR == 0) {
  40.         printf("%s\n", str2);
  41.         printf("str2 smaller than str\n");
  42.     }
  43.     return 0;
  44. }
RAW Paste Data