#include <stdio.h> #include <string.h> void process(char *istr, char *S2) { char *instr; instr = strstr(istr,S2); if(instr!=NULL) { printf("true\n"); } } void main(void) { char S1[20], S2[20]; char sp[10]=" "; char *istr; printf("Enter S1, S2\n"); gets(S1); gets(S2); istr = strtok(S1,sp); while(istr != NULL) { process(istr,S2); istr = strtok(NULL,sp); } return 0; } It is necessary to make a comparison of the lines of arbitrary content and the conclusion of the percentage of similarity. I do this, enter 2 lines, break the smaller into words, then pass the word and the line into the function, if the word in the line occurs, I increment it, then I calculate the percentage of matches. So far I want to print true if the word from the first line is found in the second. I am writing this way, because after that I will solve the same problem with the threads. The problem with this code is that it displays true only if the line in which we are looking for a word contains the word itself, for example, line 1 - (abcd) runoff 2 - (a) the result is (true), and if line 1 is (abcd ) drain 2 - (ac) as a result is empty, but should be (true true).
strstrreally looking for a direct entry of a string into a string. Space is not perceived as a section - simple symbol - DNS