Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
C code to compare two texts in form of array of chars ignoring the capitalization
//gcc 5.4.0 // C code to compare two texts in form of array of chars ignoring the capitalization // code by Twareintor #include <stdio.h> #include <string.h> #define PRINT_RESULT(X) if(X) printf("\"%s\"\n", X); else printf("same text ingore capitalization\n"); /** this function compares two array of chars apart of capitalization through comparing * every character (whose the fifth bit was set to 1) of both arrays - see the function code * - very useful for text analysis, interpretation and also in machine learning applications * for example: checking source code for case insensitive programming languages, like SQL etc. * where the execution time is an issue. */ char* strcmpIgnCase(const char* szTest, const size_t testLen, const char* szText); int main(void) { const char szTest[] = "The Quick Brown Fox Jumps Over The LaZY DOG"; const char szText[] = "tHe qUicK BROWn fOx jumPs oVEr the LazY dog!!!!!!"; const char szTeZt[] = "tHe qUicK BROWn fOx jumPs oVEr the cRazYFrog!!!!!"; char* szCmp = strcmpIgnCase(szTest, strlen(szTest), szText); PRINT_RESULT(szCmp) szCmp = strcmpIgnCase(szTest, strlen(szTest), szTeZt); PRINT_RESULT(szCmp) szCmp = strcmpIgnCase(szTest, strstr(szTeZt, "cRazY")-szTeZt-1, szTeZt); PRINT_RESULT(szCmp) return 0; } char* strcmpIgnCase(const char* szTest, const size_t testLen, const char* szText) { size_t i; // byte-by-byte (except 5-th bit) copmared along the specified length for(i=0; i<testLen; i++){if((szTest[i]|32)!=(szText[i]|32)) return szTest+i;} // printf("\"%s\"\\", szTest); return 0; }
run
|
edit
|
history
|
help
1
bitwise manipulation
DUE BY TUESDAY
22nd HW Switchv1.0
thermal_containers
pointer example 3
Tree
C assignment due sunday
structt
Assignment 3 Final
shrinken shraken shrank leave as no cold call acces program unles clownbtweak blue voda