Well you really should listen to what your compiler is telling you. First up, main returns an int, so declaring it as void is wrong. When you call your function, find_char, it should not look like you had it:
Code:
*find_char(&myString, &nyString);
This would work:
Code:
find_char(&myString[0], &nyString[0]);
Though it is not as much idiom as this:
Code:
find_char(myString, nyString);
Ok, so with your function call straightened out, on to the function:
Code:
for( i = source; i <= source; i++ )
You assign 'source' to i - which happens to be an address. Of course this does not really work for you, because i is not actually a pointer variable, but a char. Then you test if i is less than or equal to source, which it is, because you just assigned source to i. Even if i was a pointer variable, this would not make a lot of sense, as you just assigned source to i, so of course they will be equal. And then the loop ends. So you need to rework that somehow.
You should try working out on paper the steps you need to take before you actually start trying to implement it in real code.
For the function proper, it might look something like this:
Code:
check if either source or chars are NULL
if either are NULL, return NULL
After you have checked the pointers for NULL (you don't want to try dereferencing a NULL pointer) you can go ahead and see if either of the strings are empty:
Code:
check if either source or chars are empty
if either are empty, return NULL
Then we can get on with comparing the characters in 'chars' to the characters in 'source':
Code:
while there is still a character in 'source'
while there is still a character in 'chars'
does the current char in 'source' match the current char in 'chars'?
if yes, return the address of 'source'
if no, then increment to the next character of 'chars' and check again
none of 'chars' match the current character in 'source'?
increment to next character in 'source'
reset to beginning of 'chars' and start looking again
no match found?
return NULL
That should give you some ideas to think about. Also, when you want to compare actual characters, you need to dereference. So comparing 'source' and 'chars' you would do something like this:
Code:
if (*chars_pointer != '\0'
&& *chars_pointer == *source) {
return source;
Without the '*' you are comparing addresses, and not the actual value stored there. Finally, once you get this thing working, you might be interested in experimenting with different ways of improving your alogrithm. The 'pseudo-code' I demonstrated is not the most efficient algorithm - there are more efficent ways of doing it, but different ways can be explored once you get this one figured out.
~/