I am trying to have my function return # of repeated letters in a strg. Ex. mississippi has 3:i,s,p(can't count repeats) I am getting no errors but can't figure out how to get the right answer. If anyone can help thanks.
Code:
#include <stdio.h>
int repeat(char *ptr)
{
int count=0,count2,i,n=26,k=0;
char x[]="abcdefghijklmnopqrstuvwxyz";
for(i=0; i<n; i++)
{
count2=0;
while(*ptr != '\0')
{
if ((*ptr=x[i]))
count2++;
ptr++; k++;
if (count2==2)
count++;
}
ptr-=k;
}
return count;
}
int main( void)
{
int e=0;
char strg[]="mississippi";
printf("before repeat: %d \n", e);
e=repeat(strg);
printf("after repeat: %d \n", e);
return 0;
}