Skip to content

Instantly share code, notes, and snippets.

@alexesDev
Created December 25, 2012 18:50
Show Gist options
  • Select an option

  • Save alexesDev/4374775 to your computer and use it in GitHub Desktop.

Select an option

Save alexesDev/4374775 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define TEST(a, b, mustBe) \
if(mustBe != compareString(a, b)) { printf("Error > "); } \
printf("%s %s %s\n", a, compareString(a, b) ? "==" : "!=", b);
char downcaseChar(char value)
{
if(value >= 65 && value <= 90)
value += 32;
return value;
}
int compareChar(char firstChar, char secondChar)
{
return downcaseChar(firstChar) == downcaseChar(secondChar);
}
int compareString(char* firstString, char* secondString)
{
int i = 0;
for(; ; ++i)
{
if(!compareChar(firstString[i], secondString[i]))
return 0;
if(compareChar(firstString[i], '\0') && compareChar(secondString[i], '\0'))
return 1;
if(compareChar(firstString[i], '\0') || compareChar(secondString[i], '\0'))
return 0;
}
return 0;
}
int main(void)
{
TEST("Varya", "varya", 1);
TEST("Varya", "Varya", 1);
TEST("Varya1", "varya", 0);
TEST("Varya1", "varya5", 0);
TEST("I'm superman!", "I'm superman", 0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment