Wednesday, May 13, 2015

find the string




#include<stdio.h>
void stricmp(char *p,char *q);
int strilen(char*s);
main()
{
        char a[]={"the"},b[]={"the cat sat the the on the mat"};
        printf("the word is %s",a);
        printf("\nthe setence is %s",b);
        stricmp(a,b);
}
            void stricmp(char *p,char *q)
{
        char *t;
        int k,times=0,c,i;
        t=p;
        k=strilen(q);
        for(i=1; i<=k; i++)
        {
                while((*p!='\0')&&(*q!=' '))
                {
                        if(*p==*q)
                        {
                                c=1;
                        }
                        else
                        {
                                c=0;
                        }
                        q++;
                        p++;
                }
                        if(c==1)
                        {
                                times++;
                        }
                        p=t;
                        q++;
                }
        printf("\nthe word repeated at %d times",times);
}
int strilen(char *s)
{
        int len=0;
        while(*s!=0)
{
                s++;
                len++;
        }
        return len;

}

No comments:

Post a Comment