I have a problem, I need to test if a string is present in an other array in C using pointer. I tried this, but it doesn't work, if anyone has any suggestion... here is the code I tried, thank you in advance...
/* Like the strstr() function. It returns a pointer to the first occurrence of the string aiguille in the string meule_de_foin.
* @param meule_de_foin the string to search in
* @param aiguille the string to find
* @return a pointer to the first occurrence of the string aiguille in the string meule_de_foin if aiguille is in meule_de_foin, NULL otherwise
*/
const char * IMPLEMENT(indexOfString)(const char *meule_de_foin, const char *aiguille) {
int isFound; isFound=0;
int first; first=meule_de_foin;
while(isFound==0){
if(*aiguille=='\0' && *meule_de_foin=='\0'){
isFound=1;
} else if (*aiguille == *meule_de_foin){
aiguille=aiguille+1;
meule_de_foin=meule_de_foin+1;
}else{
isFound=2;
}
}
if(isFound==1){
return (first);
}else{
return(NULL);
}
}
if(isFound==1){
return (first);
}else{
return(NULL);
}
aiguilleis found at the beginning ofmeule_de_foin.firstshould beconst char *, notint.