top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

Write a C program to check whether a given character is present in a string, find frequency & position of occurrence?

0 votes
90 views

Enter character: r
Enter string: programming
Output: Positions of 'r' in programming are: 2 5
Character 'r' occurred for 2 times

posted May 16, 2017 by Pooja Singh

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

0 votes
#include<stdio.h>
int main()
{
        char str[100],ch;
        int i=0,count=0;
        printf("Enter a character\n");
        scanf("%c",&ch);
        printf("Enter string\n");
        scanf("%s",str);
        printf("Position of '%c' in %s are : ",ch,str);
        for(;str[i];i++)
        {
                if(str[i]==ch)
                {
                        printf("%d ",i);
                        count++;
                }
        }
        printf("\nCharacter '%c' occured for %d times\n",ch,count);
}
answer May 16, 2017 by Chirag Gangdev
Similar Questions
–1 vote

Write a C program to check if the given string is repeated substring or not.
ex
1: abcabcabc - yes (as abc is repeated.)
2: abcdabababababab - no

+2 votes

Output
Enter the string: Welcome to C Class!
Enter the word to insert: programming
Enter the position you like to insert: 3
The string after modification is

Welcome to C programming Class!

+2 votes

Write a C program which accept two strings and print characters in second string which are not present in first string?

Example:
String 1: apple
String 2: aeroplane

output:
ron

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...