Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
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
0
Please
log in
to post a comment.
Hello
Check EOF Value
Busqueda binaria version iterativa
C_141106_Factorial
18BCE2182 ASSESS_1 Q1-7
Lab 9 v0.96
lab6
Minus pointer
Project 3 part 2 Book v10.1
printint a struct
Please log in to post a comment.