#include<stdio.h>
#include<string.h>
int main()
{
char str[100], ch;
int i, Flag;
Flag = 0;
printf("\n Please Enter any String : ");
gets(str);
printf("\n Please Enter the Character that you want to Search for :");
scanf("%c", &ch);
for(i = 0; i <= strlen(str); i++)
{
if(str[i] == ch)
{
Flag++;
break;
}
}
if(Flag == 0)
{
printf("\n Sorry!! We haven't found the Search Character '%c'", ch);
}
else
{
printf("\n The First Occurrence of the Search Element '%c' isat Position %d ", ch, i + 1);
}
return 0;
}
Asked
Active
Viewed 26 times
0
dbush
- 186,650
- 20
- 189
- 240
-
Welcome. Please format and indent your code correctly. It will save you a lot of trouble debugging and make it much easier for others to help you. – user438383 Jan 20 '22 at 12:44