ProAnswers.org

Write a C program to find first occurrence of a given character in a string?

#include

#include 

#include 

void main() 

{ 

Char string[30],ch,*chp; 

clrscr(); 

printf(“ Enter text below”); 

gets(string); 

printf(“

character to find:”);

ch=getchar(); 

chp=strchr(string,ch); 

if(chp) 

printf(“character %c found in string”,ch); 

else 

printf(“character %c not found in string”,ch); 

getch(); 

} 

Output: 

Enter text below: anandamurugan 

Character to find: r 

Character r found in string