C program to accept a string and search a character?

1 answer

Answer

1246146

2026-05-16 13:30

+ Follow

#include<stdio.h>

#include<conio.h>

int main()

{

char str[20],charsrc;

int i,j=0,re;

printf("Enter the string\n");

gets(str);

printf("Enter the character to be searched : ");

charsrc=getche();

for(i=0;i<20;i++)

{

if(charsrc==str[i])

{

re=i;

j=1;

}

}

if(j==1)

printf("Character is at position %d",re);

else

printf("Not found.");

return 0;

}

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.