These are the instructions:
Program to implement a function strFind that accepts two strings (character arrays). The first string is the string to find and the second string is the string to search. You should return the index of the first character of the string found in the search string. Although you are returning an integer index, this program is to be otherwise pointer-based. You may find it helpful to write the program first without pointers to work through the logic and then convert it to be pointer-based.
I'm just a little confused with the pointers. if you can help me or give me example code so I can write it myself that would be great.
here is what I have:
Code:
#include <stdio.h>
#include <stdlib.h>
int strfind(char array1[], char array2[]) //declare function
{
int loopcount1 = 0;
int loopcount2 = 0;
int index = -1;//assume not found
bool found = false;
while(array2[loopcount2])
{
found = true;
printf("%c \n",array1[loopcount1]);
if(array1[loopcount1] == array2[loopcount2])
{
loopcount1++;
loopcount2++;
}
else
{
loopcount1 = 0;
loopcount2++;
}
// if(array1[loopcount1] == '\0')
if(!array1[loopcount1])
{
index = loopcount2 - loopcount1;
break;
}//end of if
} // end of while
return index;
} //end of function
char array1[] = "ta";
char array2[] = "catalog";
int main()
{
int index;
if((index = strfind(array1, array2)) != -1)
{
printf("found at %d\n",index);
}
system("pause");
return 0;
}