Squeeze(s1,s2) or squeeze(char[],char[]) is a user defined function which is used to delete the common characters or equal characters in two strings.
Problem
How to delete the common characters in two strings using squeeze function in C programming language?
Solution
In this program, the user enters two strings in the console and write a code to display first string excluding the common characters present in second string.
Example
The C program which demonstrates the functioning of squeeze function is as follows −
#include<stdio.h> void squeeze(char string1[],char string2[]);//prototype declaration int main(){ char string1[50]; char string2[30]; printf("enter the string1:"); scanf("%s",string1);// read string1 from keyboard printf("enter the string2:"); scanf("%s",string2);// read string2 from keyboard squeeze(string1,string2);//call squeeze function printf("Final string is:%s\n",string1); return 0; } void squeeze(char string1[],char string2[]){ int i,j,k; for(i=k=0;string1[i]!='\0';i++){ for(j=0;string2[j]!='\0' && string2[j]!=string1[i];j++) if(string2[j]=='\0') string1[k++]=string1[i]; } string1[k]='\0'; }
Output
The output is stated below −
Enter the string1 : Tutorial Enter the string2 : ut Final string : Torial