Pages

Saturday, August 1, 2020

SEARCHING IN STRING ARRAY



Searching in string array is like searching in an integer array.
In the following program we are going to searching a given character position in the given sentence by user.

PROGRAM TO SEARCH IN STRING
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
clrscr();
char s[60], c;
int i, L;
puts("Enter any sentence: ");
gets(s);

printf("Enter character to search:");
c=getche();

// Calculating strength of the string 
L=strlen(s);

// Loop to search character position in the string
for(i=0; i<L; i++)
{
if(c == s[i])
{
break;
}
}

printf("\nCharacter position found at the position :%d", i+1);
getch();
}


----------------------------
         OUTPUT 
----------------------------

Enter any sentence:
Computer is an example of electronic device.


Enter character to search: s
Character found at position: 11

No comments:

Post a Comment