How do you compare more than 2 or multiple strings in C language? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do you compare more than 2 or multiple strings in C language?

Comparing multiple strings in C

21st Nov 2021, 6:53 AM
Kaizuke
Kaizuke - avatar
4 Answers
+ 2
Like what for example?
21st Nov 2021, 8:11 AM
Ipang
+ 1
//by using list list a = ["a","b"] list b = ["a", "c"] for(var i in a){ for(var i in b) { if(a[i] ==b[i]) return true;} return false;}
21st Nov 2021, 8:44 AM
Julius Bright
Julius Bright - avatar
+ 1
#include <stdio.h> #include <string.h> int main() { char str[50] = "Hello"; if(strstr(str,"He") != NULL) printf("T"); else printf("F"); return 0; } //Keep learning & happy coding :D
21st Nov 2021, 8:51 AM
SoloProg
SoloProg - avatar
0
int testing(char *test, char *test1){ char name[6]; int b=0; int c = 2; int results = 0; for(int a = 0; a<=(strlen(test1)); a++){ if(test1[a] == ' ' || name[b-1] == ' '){ name[b] = '\0'; if(c%2 == 0){ if(strcmp(test,name) == 0){ results = 1; }else{ results = 0; break; } } c++; b = 0; } name[b] = test1[a]; b++; } return results; } Here's a code a wrote for comparing 2 or more strings, please add a space at the end of the string you wanna compare. Below is the example code you can run and understand how this works. #include <stdio.h> #include <string.h> int testing(char *test, char *test1){ char name[6]; int b=0; int c = 2; int results = 0; for(int a = 0; a<=(strlen(test1)); a++){ if(test1[a] == ' ' || name[b-1] == ' '){ name[b] = '\0'; if(c%2 == 0){ if(strcmp(test,name) == 0){ results = 1; }else{ results = 0; break; } } c++; b = 0; } name[b] = test1[a]; b++; } return results; } int main(){ printf("%d",testing("hello", "hello hello hello hello hello ")); }
25th Feb 2023, 12:04 PM
ajeeth bt
ajeeth bt - avatar