in turboc++
--------------------------------------------------------------------------------------
//program to count a particular character in a string.
#include <stdio.h>
#include<conio.h>
int main()
{
char string[100],sec;
int i,count=0;
printf("enter string\n");
gets(string);//accepts string
printf("enter a character\n");
sec=getchar();//accepts a character
for(i=0;string[i]!='\0';i++)//loop execution till null character
{
if(string[i]==sec)//condition testing for character
{
count++;//counting character
}
}
printf("total character=%d",count);// prints total character.
getch();
return 0;
}
--------------------------------------------------------------------------------------
//program to count a particular character in a string.
#include <stdio.h>
#include<conio.h>
int main()
{
char string[100],sec;
int i,count=0;
printf("enter string\n");
gets(string);//accepts string
printf("enter a character\n");
sec=getchar();//accepts a character
for(i=0;string[i]!='\0';i++)//loop execution till null character
{
if(string[i]==sec)//condition testing for character
{
count++;//counting character
}
}
printf("total character=%d",count);// prints total character.
getch();
return 0;
}
-----------------------------------------------------------------------------------------
in codeblocks:
------------------------------------------------------------------------------------------
//program to count a particular character in a string.
#include <stdio.h>
int main()
{
char string[100],sec;
int i,count=0;
printf("enter string\n");
gets(string);//accepts string
printf("enter a character\n");
sec=getchar();//accepts a character
for(i=0;string[i]!='\0';i++)//loop execution till null character
{
if(string[i]==sec)//condition testing for character
{
count++;//counting character
}
}
printf("total character=%d",count);// prints total character.
return 0;
}