strchr - Character Occurrence

Code :

#include <stdio.h>
#include <stdlib.h>
char xstrchr(char arr[100]);
int main()
{
    char arr[100];
    xstrchr(arr);
}
char xstrchr(char arr[100])
{
    char search_key;
    printf("Enter string: ");
    gets(arr);
    int i;
    printf("Enter word u want to search: ");
    scanf("%c",&search_key);
    for(i=0;arr[i]!='\0';i++)
    {
        if(arr[i]==search_key)
        {
            printf("\ncharacter is found in %d index",i+1);
            //break ;  // remove this comment if you want to search character only once
        }
    }
}

Post a Comment

CodeNirvana
Newer Posts Older Posts
© Copyright Encyclopedia of C | Designed By Code Nirvana
Back To Top