hello I am trying to make a strstr implmention but havent completed it yet coz i have something seriously wrong in my function there is if test inside which test char if there = then it should excute statements but it does excute statements even if there not =
!!
Code:#include <stdio.h> #include <string.h> #include <ctype.h> char *strstr2(char *SzName1,char *SzName2) { bool isFound=false; int record=0; char *SzPtr; int i; int Size; int count=0; int x=0; //run loop to the biggest count of the 2 Size = strlen(SzName1) > strlen(SzName2) ? strlen(SzName1)-1 : strlen(SzName2)-1 ; for(i=0; i < Size ; i++ ) { if(SzName2[x]==SzName1[i]) { printf("SzName2[x]=%c and SzName[1]=%c\n",SzName2[x],SzName1[x]); getchar(); x++; record=i; isFound=true; count++; } if(isspace(SzName1[i]) && count!=(strlen(SzName2)-1) ) { isFound=false; record=0; count=0; } } return isFound ? SzPtr : SzPtr='\0'; } int main(void) { char *SzPtr;//return ptr where it find the name the address char SzName1[]="name"; char SzName2[]="thats a good name bro"; SzPtr=strstr2(SzName2,SzName1); printf("%s",SzPtr ? SzPtr : "didnt find specefied string" ); return 0; }