counting the occurrence of a character in a string
#include <stdio.h>
int occurence(char *c, char s)
{
char * ptr=c;
int count=0;
while(*ptr!='\0')
{
if(*ptr==s)
{
count++;
}
ptr++;
}
return count;
}
int main(){
int number;
char s='a';
char str[]="anchalaggarwal";
number=occurence(str,s);
printf("The occurence of character %c in the string is:%d",s,number);
return 0;
}
Comments
Post a Comment