WAP to Accept 2 strings and display how many times each character from 1st string occurs in 2nd string.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void count(char *s1,char *s2);

main()
{
      char str1[20],str2[20];
      printf("enter two strings");
      scanf("%s",str1);
      scanf("%s",str2);

      count(str1,str2);

printf("\n");
 system("pause");
}

void count(char *s1,char *s2)
{
   int c,n1,n2,i;
  char *s;
 s=s2;

  while(*s1!='')
  {

  c=0;

  s2=s;
      while(*s2!='')
      {
 if(*s1==*s2)
 c++;
 s2++;
      }
printf("no. of times letter %c appeared in %s is %d ",*s1,s,c);
printf("\n");
s1++;
     }

}
Advertisements

Leave a comment

Filed under TUTORIALS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s