Skip to content

Instantly share code, notes, and snippets.

@Sammyjroberts
Created June 25, 2015 04:51
Show Gist options
  • Save Sammyjroberts/11fa60148d2cf537b3fa to your computer and use it in GitHub Desktop.
Save Sammyjroberts/11fa60148d2cf537b3fa to your computer and use it in GitHub Desktop.
here is my function call in main
char str[] = {'p','n','o','t','S','a','n','o','t', NULL};
char tar[] = {'n','o','t', NULL};
char *retStr[10];
int num;
num = MultiStrStr(str,tar,retStr);
unsigned int MultiStrStr(const char* str, const char* target, char** retStrings)
{
int lcv = 0;
const char* returnChar;
int totalOccurances = 0;
while(str[lcv] != NULL) //loop through character array
{
if(str[lcv] == target[0]) //if first character found
{
int strLcv = lcv;
int tarLcv = 0;
while (str[strLcv] == target[tarLcv] && target[tarLcv] != NULL)
{
//loop through and check if equal till target is null
strLcv++;
tarLcv++;
}
if(target[tarLcv] == NULL) //if we reached the end of the target string
{
cout << str[lcv] << endl;
retStrings[totalOccurances] = &str[lcv];
totalOccurances++;
}
}
lcv++;
}
return totalOccurances;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment