Sunday, January 20, 2019

read two strings and test whether all chars of first string present in second string

#include<stdio.h>
#include<string.h>
int test(char*str1,char *str2)
{
    int ctr1=0,ctr2=0,i,j;
for(j=0;str1[j]!=0;j++)
{
    for(i=0;i<strlen(str1);i++)
    if(str1[i]==str1[0])
    ctr1++;
   
    for(i=0;i<strlen(str2);i++)
    if(str2[i]==str1[0])
    ctr2++;
   
 
    if(ctr1==ctr2)
    {
        j++;
   
    continue;
    }
    else
    return -1;
   
}
return 1;
}

int main() {
   char*s1="ab";
   char*s2="aa";
   printf("%d",test(s1,s2));
}

input :
abc      cba
1

ab  aa
-1






No comments:

Post a Comment