Write a function occur(string, char) that returns the number of occurrences of that character in the string.

#include<stdio.h>
#include<conio.h>
int strchr(char [],char );
void main()
{
char a[80],b;
int i;
clrscr();
printf("Enter 1st string\n");
gets(a);
printf("Enter character to find occurence\n");
fflush(stdin);
scanf("%c",&b);
i=strchr(a,b);
if(i!=0)
printf("The character occured at %d position\n",i);
printf(" Sorry! the character is not present in the string");
getch();
}
 int strchr(char a[],char y)
 {
 int i,j;
 for(i=0;a[i]!=y&&a[i];i++);
  if(a[i]=='\0')
  return (0);
  return(i);

 }

No comments:

Post a Comment

Related Post

Array:
String functions:
General (Loops-for/while)
Write a Program to print reverse of a given number Write a Program to print Product of Digits (eg. 212=2*1*2=4) of a given number Write a C++ Program to Convert Binary into Decimal Number