C Examples Frequency Character
# C Programming Example - Find the Number of Occurrences of a Character in a String
[ C Programming Example](#)
Find the starting position of a character in a string (index starts from 0).
## Example
#includeint main(){char str, ch; int i, frequency = 0; printf("Enter a string: "); fgets(str, (sizeof str / sizeof str), stdin); printf("Enter the character to find: "); scanf("%c",&ch); for(i = 0; str != ''; ++i){if(ch == str) ++frequency; }printf("Character %c occurs %d times in the string.", ch, frequency); return 0; }
The output is:
Enter a string: Enter the character to find: o Character o occurs 2 times in the string.
[ C Programming Example](#)
YouTip