Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://en.wikibooks.org/wiki/C_Programming/C_Reference/nonstandard/strcasecmp
- #include <stdio.h>
- #include <stdlib.h>
- #include <strings.h>
- int main ()
- {
- int i;
- char str1[]="test";
- char str2[]="Test";
- char str3[]="Testing";
- char str4[]="Testing 555";
- char str5[]="testing 555";
- char str6[]="Testing 123";
- printf("(1)\n");
- i = strcasecmp(str1, str2);
- if (i == 0)
- printf("'%s' equals '%s'\n", str1, str2);
- else if (i > 0)
- printf("'%s' is greater than '%s'\n", str1, str2);
- else if (i < 0)
- printf("'%s' is less than '%s'\n", str1, str2);
- printf("(2)\n");
- i = strcasecmp(str1, str3);
- if (i == 0)
- printf("'%s' equals '%s'\n", str1, str3);
- else if (i > 0)
- printf("'%s' is greater than '%s'\n", str1, str3);
- else if (i < 0)
- printf("'%s' is less than '%s'\n", str1, str3);
- printf("(3)\n");
- i = strcasecmp(str3, str1);
- if (i == 0)
- printf("'%s' equals '%s'\n", str3, str1);
- else if (i > 0)
- printf("'%s' is greater than '%s'\n", str3, str1);
- else if (i < 0)
- printf("'%s' is less than '%s'\n", str3, str1);
- printf("(4)\n");
- i = strcasecmp(str4, str6);
- if (i == 0)
- printf("'%s' equals '%s'\n", str4, str6);
- else if (i > 0)
- printf("'%s' is greater than '%s'\n", str4, str6);
- else if (i < 0)
- printf("'%s' is less than '%s'\n", str4, str6);
- printf("(5)\n");
- i = strcasecmp(str5, str6);
- if (i == 0)
- printf("'%s' equals '%s'\n", str5, str6);
- else if (i > 0)
- printf("'%s' is greater than '%s'\n", str5, str6);
- else if (i < 0)
- printf("'%s' is less than '%s'\n", str5, str6);
- return 0;
- }
- /*
- output:
- (1)
- 'test' equals 'Test'
- (2)
- 'test' is less than 'Testing'
- (3)
- 'Testing' is greater than 'test'
- (4)
- 'Testing 555' is greater than 'Testing 123'
- (5)
- 'testing 555' is greater than 'Testing 123'
- */
Advertisement
Add Comment
Please, Sign In to add comment