I am trying to write a function(findString) to find out if character strings are present inside another string. For my function, the first argument is the searched character string and the second is the one trying to be found.
If the string is found, then the location of the source string is returned.
My written code is below:
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
int findstring(char source[], char lookup[]){
int lensource, lenlookup;
lensource= strlen(source);
lenlookup = strlen(lookup);
int i;int j;
for(i=0; i>=lensource; ++i)
for (j=0; j>=lenlookup; ++j)
if (source[i]==lookup[j])
return i;
}
int main(){
findstring("Heyman","ey");
}
If the function worked properly, then the index 2 should be returned.
However, when I run it, nothing is returned. I suppose the problem it that there is something wrong with my approach with the for loop or if statement.
I'm doing this without using strstr
findstring()...