Position of character and How many times character repeat in string

Q. write a C program to accept a string from user and after that accept a single character from user and search whether this character include in string or not if is is include then find out the position of character and also calculate, how many times character repeat?

For example:

Entered string : This is C programming
Entered character for search: p

Position of p in string : 11
Repeation of p in string : 1


/*c program for search character and if is include then how many times present in string*/
int searchChar(char [], char);
int repeatChar(char [], char);
int main()
 char str[100];
 char search;
 int count,repeat,posi;
 printf("Enter any string : ");
 for(count=0; ((str[count]=getchar())!='\n'); ++count);
 printf("Enter character for search : ");
 scanf("%c", &search);
 posi = searchChar(str,search);
 repeat = repeatChar(str,search);
 if(posi == -1)
   printf("\nEntered  character is not found...");
   printf("\nPosition of %c in string = %d\n",search,posi+1);
   printf("\nRepeation of %c in string = %d\n",search,repeat);
 return 0;

/*function for search character*/
int searchChar(char str[], char ch)
 int i;
 for(i=0; str[i]!='\0'; i++)
      return i;
 return -1;

/*function for calculate frequency of character*/
int repeatChar(char str[], char ch)
 int i,rep=0;
 for(i=0; str[i]!='\0'; i++)
 return rep;


Output of search character from string & find out its repetition
Screen shot for search character in string and find its frequency

Related programs:

  1. Reverse all string
  2. Reverse all words but not string
  3. Reverse only first character of string & add extra character
  4. Display string vertically
  5. Search sub string from main string
  6. Search sub string individual from main string
  7. Change title case of string


  1. thnk u very much..!!!

    I rily apreciate it...!!!

    hope i too may cm help to u in future..!!!