Count charectars in a word or sentance in C language
This programme can count number of chatectars using C language. For example: softplanet24 has 12 charectars.
#include <stdio.h>
int main()
{
int i=0, j, count=0;
char str[80], ch;
printf("Enter a word or sentence: ");
gets(str);
while(str[i] != '\0')
i++;
printf("Enter a charectar to count it: ");
ch=getchar(); //or, scanf("%c", &ch);
for(j=0; j<=i; j++)
if(str[j] == ch)
count++;
printf("\n %c = %d\n", ch, count);
return 0;
}
No comments :
Post a Comment