Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a function removeWhite(const char *str1, char *str2) that removes all spa

ID: 3685983 • 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. Submit your source code strProcessing.c through Handin.

Explanation / Answer

Solution for Question:

This below code will work as per given problem statement and it have the two functions.

See the below code:

// An efficient C program to remove all spaces
// from a string
#include <iostream>
using namespace std;

// Function to remove all spaces from a given string
void removeSpaces(char *str)
{
// To keep track of non-space character count
int count = 0;

// Traverse the given string. If current character
// is not space, then place it at index 'count++'
for (int i = 0; str[i]; i++)
if (str[i] != ' ')
str[count++] = str[i]; // here count is
// incremented
str[count] = '';
}

int bigString()
{
   char str[80], search[10];
int count1 = 0, count2 = 0, i, j, flag;

printf("Enter a string:");
gets(str);
printf("Enter search substring:");
gets(search);
while (str[count1] != '')
count1++;
while (search[count2] != '')
count2++;
for (i = 0; i <= count1 - count2; i++)
{
for (j = i; j < i + count2; j++)
{
flag = 1;
if (str[j] != search[j - i])
{
flag = 0;
break;
}
}
if (flag == 1)
break;
}
if (flag == 1)
printf("SEARCH SUCCESSFUL!");
else
printf("SEARCH UNSUCCESSFUL!");
}
// Driver program to test above function
int main()
{
char str[] = "g eeks for ge eeks ";
removeSpaces(str);
printf("After Removing Spaces is %s :",str);
   bigString();
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote