never ever for any reason use gets(). Here's why .
>>Could it have something to do with using gets()?
Yes. instr can only hold 9 characters plus the null terminator and you are trying to stuff more than that into it. gets() is scribbling the overflow all over your program's memory.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
two problems:
1) line 29: initialize the pointer to NULL because if the loop beginning on line 31 never finds the first character of the string then the function needs to return a valid pointer -- NULL.
2) Add a break just after the end of the loop on line 43 because at that point it has found the string so no point in looking any further.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
The first argument to strncmp() is a const char* pointer, but you are just passing a single character.
Suggest you change line 8 like this: if (strncmp (&str2[i], str1, strlen(str1)) == 0)
Actually there is an easier way to do this using strstr().
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343