Answers for "how to count the letters in C code"

C
0

find character from string c count

#include <stdio.h>
#include <string.h>
 
int main()
{
    char s[1000],c;  
    int i,count=0;
 
    printf("Enter  the string : ");
    gets(s);
    printf("Enter character to be searched: ");
    c=getchar();
    
    for(i=0;s[i];i++)  
    {
    	if(s[i]==c)
    	{
          count++;
		}
 	}
     
	printf("character '%c' occurs %d times n ",c,count);
 
 	 
     
    return 0;
}
Posted by: Guest on December-02-2020
0

program in C to count total number of alphabets, digits and special characters in a string.

#include <stdio.h>
#include <string.h>
 
int main()
{
    char s[1000]; 
    int i,alphabets=0,digits=0,specialcharacters=0;
 
    printf("Enter  the string : ");
    gets(s);
     
    for(i=0;s[i];i++)  
    {
        if((s[i]>=65 && s[i]<=90)|| (s[i]>=97 && s[i]<=122) )
          alphabets++;
        else if(s[i]>=48 && s[i]<=57)
         digits++;
        else
         specialcharacters++;
 
 	}
 	
     
    printf("Alphabets = %dn",alphabets);
    printf("Digits = %dn",digits);
    printf("Special characters = %d", specialcharacters);
    
 
    return 0;
}
Posted by: Guest on September-08-2021
-1

C program to find no of chars

Total number of characters in a string: 19
Posted by: Guest on June-07-2021

Code answers related to "how to count the letters in C code"

Code answers related to "C"

Browse Popular Code Answers by Language