Originally Posted by
Martyn27
What if there is multiple occurences of a char on a single line?
Well, you want to process the entire line, yeah. Something like:
Code:
char str[]="the quick brown i jumps over the lazy i.\n", *ptr = str;
while ((ptr = strchr(ptr,'i'))) {
IMO this is going to be more awkward, it is easier to just go:
Code:
char str[]="the quick brown fox i jumps over the lazy dog i.\n";
int x, len = strlen(str);
for (x=0;x<len;x++)
if (str[i] == 'i' &&
I left that incomplete because you will need a more complete and complex set of conditions -- eg, if "i" must have a space on either side, then the for might as well be:
for(x=1;x<len-1;x++);
And you can just check to see that str[i-1] and str[i+1] are spaces. But I thought I'd also point out that if you have an i outside of a word at the beginning or end of the line, does that count (eg "the lazy dog i.\n")?