Saturday, August 20, 2011

Find occurance of given character in string.

//Program to find occurance of given character in string.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[20],c;
int o,i,l;
clrscr();
printf("program to find occurance of given character in string");
printf("\n Enter the string: ");
gets(str);
l=strlen(str);
printf("Please enter the character whose number of occurances u want to find: ");
c=getche();
o=0;
for(i=0;i<l;i++)
{
 if(str[i]==c)
 {
 o=o+1;
 }
}
printf("\n the number of occurances of given character is %d",o);
getch();
}

Previous Next Home
0 Comments
Comments

Leave a Comment

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Twitter Delicious Facebook Favorites More