Quzah, thanks for your help, I tried to build the function and it works:
Code:
#include <stdio.h>
#include <string.h>
/* the function to check if a substring is contained in a string */
int strfind(const char *source, const char *what, const char *start);
int main(void)
{
char *strTest = "ledicia"; /* full string */
char *strFind = "dicis"; /* substring to find in full string */
printf("The full string is: %s\n",strTest);
printf("We'll search for the \"%s\" substring\n",strFind);
if(strfind(strTest,strFind,strFind))
printf("yes, the susbtring was found in the string\n");
else
printf("no, the substring wasn't found in the string\n");
printf("Press any key...\n");
getchar(); /* pause */
return 0;
}
int strfind(const char *source, const char *what, const char *start)
{
int corr, len = strlen(what);
corr = 0;
while(*source && corr <= len) {
if(*source == *what) {
++source;
++what;
++corr;
}
else {
++source;
what = start;
}
}
if(corr == len)
return 1;
return 0;
}
Hmm, thanks for you explaining me a simple way to do that
Just a simple question, when I do ++ to an pointer, he move's on the memory, but if I want to go back to the start? I used another variable, but maybe I'm missing something?