I'm having some problems with a simple function call I'm trying to write; basically, the function takes a string and a character argument and returns a pointer to the first instance of that character in the string. The call in this instance uses a for loop to use pointers to strings to print out 4 strings. I've tried fiddling around with a bunch of things but can't get the function and call to work. Any help would be greatly appreciated.
#include <stdio.h>
#define NUMBER 4
char * strsrch(char * string, char x);
int main(void)
{
char * ptr[NUMBER];
int x;
char * word[NUMBER] = {"This is string 1", "Now string 2", "Proceeding through string 3", "And then, the last string"};
for(x = 0; x < NUMBER; x++)
puts(word[x]);
for(x = 0; x < NUMBER; x++)
puts(strsrch(word[x], 'i'));
return 0;
}
char * strsrch(char * string, char x)
{
while (*string && (*string != x))
string++;
if (*string = x)
return string;
else
return NULL;
}