/  C Programs   /  C program to search given string from set of strings

C program to search given string from set of strings

#include<stdio.h>
#include<string.h>
main()
{
char a[5][10],b[10];
int i,n;
printf("enter no of strings:");
scanf("%d",&n);
printf("enter strings:\n");
for(i=0;i<5;i++)
scanf("%s",a[i]);
printf("enter a search string:");
scanf("%s",b);
printf("given strings are: ");
for(i=0;i<5;i++)
printf("%s\t",a[i]);
printf("\n");
for(i=0;i<n;i++)
{
if(strcmp(a[i],b)==0)
{
printf("string found at %d position\n",i);
break;
}
}
}

 

Output:

 

C program to search given string from set of strings

 

Leave a comment