Looking for a simple function code that would help find all

Looking for a simple function code that would help find all the index of a given character in a string using pointers.

e.g. in a string name s1, I\'d like to find every occurrence of c. This is what I think could work,

for (i=0; i< strlength; i++) {

     int count=0;

     index (s1, c)

     count++;

}

printf(\"the number of time c appeared in the string is %d\", count);

Thanks

Solution

int count=0;

for (i=0; i< strlength; i++) {
if(s1[i]==c)
{
    count++;
}
}
printf(\"the number of time c appeared in the string is %d\", count);

Looking for a simple function code that would help find all the index of a given character in a string using pointers. e.g. in a string name s1, I\'d like to fi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site