Ticker

6/recent/ticker-posts

C Language (Searching in string array)

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







STRING PALINDROME IN C >>






Post a Comment

0 Comments