C program to find first occurrence of any character.

#include<stdio.h>
#include<string.h>
int main()
{
char str[150],c;
int temp=0,i;
printf("Enter a string: ");
fgets(str,150,stdin);
printf("Enter character you want to find: ");
c=getchar();
for(i=0;i<strlen(str)&&str[i]!=c;++i);   
if(i<strlen(str))
{
printf("\n Hey,Character '%c' is found in string at position:->%d",c,i+1);
}
else
{
   printf("\n Sorry,Character %c is not found.",c);
}
return 0;
}

    

***Input && Output***



Post a Comment

0 Comments