Create a function removeWhite(const char *str1, char *str2) that removes all spa
ID: 3687215 • Letter: C
Question
Create a function removeWhite(const char *str1, char *str2) that removes all spaces inside str1 and stores the resulting string in str2. Create a function substring(const char *big, const char *small) that takes two strings as parameters and returns 1 if the string small is included in the string big (without using string.h functions strstr or strchr) Write a program (strProcessing.c) that uses the two functions you wrote. Your program should first ask the user to enter a string (possibly containing spaces). It should then use removeWhite to compute the new corresponding string without spaces and print it to the standard output. Next, your program should ask the user to enter two strings, read them and outputs one of the following statements accordingly: The string XXXX contains the string YYYY. The string XXXX does not contain the string YYYY. Where XXXX and YYYY are replaced by the actual strings entered by the user.Explanation / Answer
#include<stdio.h>
#include<conio.h>
int stlen(char str[50]) // this function used for the first string
{
int len = 0;
while(str[len]!=') // check the condition the length of the string is 0 or not
len++;
len–;
return len;
}
void stcat(char str1[50], char str2[50]) // declared function for chek the two strrings are equal or not
{
int m = 0,len = 0;
while(str1[len]!=’)
len++;
while(str2[i]!=’)
{
str1[len] = str2[m];
m++;
len++;
}
str1[len] = ‘’;
}
void main()
{
char str1[50], str2[50], str3[50], temp[50];//declare variabls
int len1, len2, len3, m,n, match, k;
clrscr();
printf(" enter the string");//enter the sentence or string
gets(str1);
len1 = stlen(str1);
printf(" enter the string want to be delete "); // enter the string which you want to be delete
gets(str2);
len2 = stlen(str2);
printf(" enter new string for replace ");
gets(str3);
len3 = stlen(str3);
for(m=0;m<=len1;m++)
{
match = 1;
for(n=0;n<=len2;n++)
if(str2[n]!=str1[m+n])
{
match = 0;
break;
}
if(match)
{
for(k=0,n=m+len2+1;n<=len1;n++,k++)
temp[k] = str1[n];
temp[k] = ‘’;
for(n=0;n<=len3;n++)
str1[m+n] = str3[n];
str1[m+n] = ‘’;
stcat(str1,temp);
len1 = len1 – len2 +len3;
m =m + n;
}
}
printf(" the string is …: ");
puts(str1);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.