C program to compare and remove all characters in second string which are present in both strings or that are common alphabets.
In this tutorial we will learn or discuss that how to write a c program code to remove all alphabets that are common in both strings.
This c program code will compare two strings and remove common letters from second string.
In the first user will enter first and second string through the keyboard then the compiler will compare both strings,r remove common alphabets in string 2 and print the second string(reminder string).
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int x=0,y,z=0,flag=0,len1,len2;
char st1[100],st2[100],temp[100]={0};
clrscr();
printf("\n ENTER FIRST STRING:\n ");
gets(st1);
printf("\n ENTER SECOND STRING:\n ");
gets(st2);
len1=strlen(st1);
len2=strlen(st2);
for(x=0;x<len2;x++)
{
flag=0;
for(y=0;y<len1;y++)
{
if(st2[x]==st1[y])
{
flag=1;
}
}
if(flag==0)
{
temp[z]=st2[x];
z++;
}
}
temp[x]='\0';
printf("\n AFTER REMOVING SAME(COMMON) ALPHABETS FROM STRING 2");
printf("\n ");
printf("\n THE SECOND STRING IS:%s\n",temp);
getch();
}
In this tutorial we will learn or discuss that how to write a c program code to remove all alphabets that are common in both strings.
This c program code will compare two strings and remove common letters from second string.
In the first user will enter first and second string through the keyboard then the compiler will compare both strings,r remove common alphabets in string 2 and print the second string(reminder string).
PROGRAM CODE
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int x=0,y,z=0,flag=0,len1,len2;
char st1[100],st2[100],temp[100]={0};
clrscr();
printf("\n ENTER FIRST STRING:\n ");
gets(st1);
printf("\n ENTER SECOND STRING:\n ");
gets(st2);
len1=strlen(st1);
len2=strlen(st2);
for(x=0;x<len2;x++)
{
flag=0;
for(y=0;y<len1;y++)
{
if(st2[x]==st1[y])
{
flag=1;
}
}
if(flag==0)
{
temp[z]=st2[x];
z++;
}
}
temp[x]='\0';
printf("\n AFTER REMOVING SAME(COMMON) ALPHABETS FROM STRING 2");
printf("\n ");
printf("\n THE SECOND STRING IS:%s\n",temp);
getch();
}
OUTPUT:
Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com
Created by-- HARSH CHAUHAN
No comments:
Post a Comment