Answers for "count the amount of letters in a string in c"

C
1

count number of words in a string in c

/*
 * C Program to Count Number of Words in a given Text Or Sentence
 */
#include <stdio.h>
#include <string.h>
 
void main()
{
    char s[200];
    int count = 0, i;
 
    printf("Enter the string:n");
    scanf("%[^n]s", s);
    for (i = 0;s[i] != '';i++)
    {
        if (s[i] == ' ' && s[i+1] != ' ')
            count++;    
    }
    printf("Number of words in given string are: %dn", count + 1);
}
Posted by: Guest on June-21-2021
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

Code answers related to "count the amount of letters in a string in c"

Code answers related to "C"

Browse Popular Code Answers by Language