Find Character From String C Count

[Solved] Find Character From String C Count | C - Code Explorer | yomemimo.com
Question : count characters in c

Answered by : jos-roberto-miranda-0ghpgb9fdq4h

#include <stdio.h>
#include <string.h>
int main(){
while(true){ char string[100]; char letter[100]; int count = 0; printf("Enter a word/sentence:\n"); scanf(" %[^\n]s",string); printf("Enter a letter:\n"); scanf(" %c",&letter); //when using scanf for a sentence/word or character, always include a space afterwards. //Counts each character except space for(int i = 0; i < strlen(string); i++) { if(string[i] == letter[0]){ count++; } } //Displays the total number of characters present in the given string printf("Total number of characters in the string: %d\n", count); printf("%s\n",string);
} return 0;
}

Source : https://stackoverflow.com/questions/3745653/counting-characters-in-c | Last Update : Sat, 10 Sep 22

Answers related to find character from string c count

Code Explorer Popular Question For C