Write a C Program that search an item from array of string
1: #include<stdio.h>
2: #include<conio.h>
3: #include<string.h>
4: int string(char[],char[]);
5: int main()
6: {
7: char str[100],find[20];
8: int i;
9: clrscr();
10: printf("Enter the string :");
11: gets(str);
12: printf("Enter the srting that you want to find : ");
13: gets(find);
14: i=string(str,find);
15: if(i==1)
16: printf("%s is found in %s",find,str);
17: else
18: printf("%s is not found in %s",find,str);
19: getch();
20: return 0;
21: }
22: int string(char str[20], char find[20])
23: {
24: int i,j,flag;
25: for(i=0;str[i];i++)
26: {
27: if(str[i]==find[0])
28: {
29: flag=1;
30: for(j=1;find[j];j++)
31: {
32: if(str[i+j]!=find[j])
33: {
34: flag=0;
35: break;
36: }
37: }
38: if(flag==1)
39: break;
40: }
41: }
42: return flag;
43: }
No comments:
Post a Comment