Skip to content

Instantly share code, notes, and snippets.

@alexesDev
Last active December 10, 2015 03:29
Show Gist options
  • Select an option

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

Select an option

Save alexesDev/4375026 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);
//Функция сравнивает две строки (часть 1)
//игнорируя различия в регистрах. (часть 2)
char upperChar(char value)
{
if(value >= 97 && value <= 122)
value -= 32;
return value;
}
int compareString(char* firstString, char* secondString)
{
int i = 0;
for(; ; ++i)
{
char firstChar = upperChar(firstString[i]);
char secondChar = upperChar(secondString[i]);
if(firstChar != secondChar)
return 0;
if(firstChar == '\0' && secondChar == '\0')
return 1;
if(firstChar == '\0' || secondChar == '\0')
return 0;
}
return 0;
}
int main(void)
{
TEST(string, "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