RicardasSim

strcasecmp

Jul 5th, 2019
947
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.00 KB | None | 0 0
  1. //https://en.wikibooks.org/wiki/C_Programming/C_Reference/nonstandard/strcasecmp
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <strings.h>
  6.  
  7. int main ()
  8. {
  9.  
  10.     int i;
  11.  
  12.     char str1[]="test";
  13.     char str2[]="Test";
  14.     char str3[]="Testing";
  15.     char str4[]="Testing 555";
  16.     char str5[]="testing 555";
  17.     char str6[]="Testing 123";
  18.  
  19.  
  20.     printf("(1)\n");
  21.  
  22.     i = strcasecmp(str1, str2);
  23.  
  24.     if (i == 0)
  25.         printf("'%s' equals '%s'\n", str1, str2);
  26.     else if (i > 0)
  27.         printf("'%s' is greater than '%s'\n", str1, str2);
  28.     else if (i < 0)
  29.         printf("'%s' is less than '%s'\n", str1, str2);
  30.    
  31.     printf("(2)\n");
  32.  
  33.     i = strcasecmp(str1, str3);
  34.  
  35.     if (i == 0)
  36.         printf("'%s' equals '%s'\n", str1, str3);
  37.     else if (i > 0)
  38.         printf("'%s' is greater than '%s'\n", str1, str3);
  39.     else if (i < 0)
  40.         printf("'%s' is less than '%s'\n", str1, str3);  
  41.  
  42.     printf("(3)\n");
  43.  
  44.     i = strcasecmp(str3, str1);
  45.  
  46.     if (i == 0)
  47.         printf("'%s' equals '%s'\n", str3, str1);
  48.     else if (i > 0)
  49.         printf("'%s' is greater than '%s'\n", str3, str1);
  50.     else if (i < 0)
  51.         printf("'%s' is less than '%s'\n", str3, str1);
  52.  
  53.     printf("(4)\n");
  54.  
  55.     i = strcasecmp(str4, str6);
  56.  
  57.     if (i == 0)
  58.         printf("'%s' equals '%s'\n", str4, str6);
  59.     else if (i > 0)
  60.         printf("'%s' is greater than '%s'\n", str4, str6);
  61.     else if (i < 0)
  62.         printf("'%s' is less than '%s'\n", str4, str6);
  63.  
  64.     printf("(5)\n");
  65.  
  66.     i = strcasecmp(str5, str6);
  67.  
  68.     if (i == 0)
  69.         printf("'%s' equals '%s'\n", str5, str6);
  70.     else if (i > 0)
  71.         printf("'%s' is greater than '%s'\n", str5, str6);
  72.     else if (i < 0)
  73.         printf("'%s' is less than '%s'\n", str5, str6);
  74.  
  75.    return 0;
  76.  
  77. }
  78.  
  79. /*
  80.  
  81. output:
  82.  
  83. (1)
  84. 'test' equals 'Test'
  85. (2)
  86. 'test' is less than 'Testing'
  87. (3)
  88. 'Testing' is greater than 'test'
  89. (4)
  90. 'Testing 555' is greater than 'Testing 123'
  91. (5)
  92. 'testing 555' is greater than 'Testing 123'
  93.  
  94.  
  95. */
Advertisement
Add Comment
Please, Sign In to add comment