Computer Scientists are Pretty Pessimistic

Friday 4 September 2015

Write a function to search a string in the array of strings. String and array of strings should be passed to the function as parameters.

#include <stdio.h>
#include <string.h>
void check (char str[],char a_str[]);
void main()
{
    char str[100],a_str[100];
    printf("Enter string:\n");
    gets(str);
    printf("Enter array of string:\n");
    getchar();
    gets(a_str);
    check(str,a_str);
}
void check (char str[],char a_str[])
{
    int i,j,c,k;
    for(i=0;i<a_str[i];i++)
    {
        c=0;
        if(a_str[i]==str[0])
        {
            for(k=i,j=0;str[j];j++,k++)
            {
                if(str[j]==a_str[k])
                    c++;
            }
        }
        if(c==(strlen(str)))
            break;
    }
    if(c==(strlen(str)))
        printf("Found\n");
    else
        printf("Not Found\n");
}

No comments:

Post a Comment