Showing posts with label Common characters in Strings. Show all posts
Showing posts with label Common characters in Strings. Show all posts

Accept 2 String and display common chars in them.

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

void main()
{
char a[80],b[80];
int i,j,t;
clrscr();
printf("Enter 1st string\n");
gets(a);
fflush(stdin);
printf("Enter 2nd string\n");
gets(b);
printf("Common characters are :\n");
 for(i=0;a[i]!='\0';i++)
 {
  for(j=i-1;j>=0;j--)

   if(a[i]==a[j])
   break;
   if(j==-1)
   for(t=0;b[t]!='\0';t++)

     if(a[i]==b[t])
    {
     printf("%c",a[i]);
     break;
    }
  }

 getch();
}

Related Post

Array:
String functions:
General (Loops-for/while)
Write a Program to print reverse of a given number Write a Program to print Product of Digits (eg. 212=2*1*2=4) of a given number Write a C++ Program to Convert Binary into Decimal Number