fork download
  1. #include <ctype.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. int strincmp(char const* s1, char const* s2, int n)
  6. {
  7. /* case insensitive comparison */
  8. int d;
  9. while (--n >= 0) {
  10. d = (tolower(*s1) - tolower(*s2));
  11. if ( d != 0 || *s1 == '\0' || *s2 == '\0' )
  12. return d;
  13. ++s1;
  14. ++s2;
  15. }
  16. return(0);
  17. }
  18.  
  19. int main()
  20. {
  21. printf( "%i\n", strincmp("cdefg", "CD", 2) );
  22. printf( "%i\n", strincmp("cd", "CDe", 2) );
  23. printf( "%i\n", strincmp("cd", "cde", 2) );
  24. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
0
0
0