-
Notifications
You must be signed in to change notification settings - Fork 0
/
35_squeeze_string.c
51 lines (45 loc) · 1.44 KB
/
35_squeeze_string.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* Author: Girish Gaude
* Date: 11/Jan/2020
* Desciption: Program that perform alternative version of squeeze(str1, str2) that deletes each character in s1 that matches any character in the string s2
* Input: Enter the two String.
* Output: Display squeeze output.
*/
#include<stdio.h>
void squeeze( char *str1, char *str2 ) //Function to squeeze two string
{
int match = 0; //Define variable to count matching word
for ( int i=0; str1[i] != '\0'; i++ ) //Run loop till nul
{
for ( int j=0; str2[j] != '\0'; j++ ) //Run loop till nul
{
if ( str1[i] == str2[j] ) //Compare each char of two string
match += 1; //Increament match variable if match
}
if( match == 0 ) //If match is zero in one itration
{
printf("%c",str1[i]); //Print that charcter
}
else
match = 0; //If Char match then skip that char and make match to zero again
}
}
int main()
{
char ch;
do
{
char str1[100],str2[100]; //Define two string
printf("Enter First String\n");
scanf("%99[^\n]", str1); //Ask user to enter string 1
getchar(); //Clear buffer
printf("Enter Second String\n");
scanf("%99[^\n]", str2); //Ask user to enter string 2
squeeze( str1, str2 ); //Call funtion and pass both string
printf("\nDo you want to continue.\n");
getchar();
scanf("%c", &ch); //If want to continue again
getchar();
}while( ch == 'y' );
return 0;
}