Wednesday, 19 February 2014

write a program to find how many time a character occure in a string using functon (without use of predefined library functon).


#include<stdio.h>
int xstrchr(char*,char);
int main()
{
char s[100],ch,*p;
int n;
printf("enter the string:\t");
gets(s);
printf("enter the character:");
scanf("%c",&ch);
n=xstrchr(s,ch);
printf("character %c is found %d times in given string",ch,n);
return  0;
}
int xstrchr(char*s,char ch)
{
int i,j,num=0;
for(i=0;s[i];i++)
{
if(s[i]==ch)
{
num++;
}
}
return num;
}

No comments:

Contact Form

Name

Email *

Message *