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: 3687012 • 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 am 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<string.h>

void removeWhite(const char *str1, char *str2);
int substring(const char *big, const char *small);

int main(){
  
   char str1[30] = "i am an intelligent man";
   char str2[20];
  
   //printf("Enter string1: ");
   //fgets(str1, 30, stdin);
  
  
   printf("Strin1: %s ", str1);
  
   //replacing spaces from 1 and storing in 2
   removeWhite(str1, str2);
  
   // printing str2
   printf("Strin2: %s ", str2);
  
   //checking a word is present in string2 or not
   int status = substring(str2, "man");
   if(status)
       printf("String %s contains man ",str2);
   else
       printf("String %s does not contains man ",str2);
  
   return 0;
}

void removeWhite(const char *str1, char *str2){
  
   int i=0;
   int j=0;
  
   while(str1[i] != ''){
       if(str1[i] != ' ')
           str2[j++] = str1[i];
       i++;
   }
  
   str2[j] = '';
}

int substring(const char *big, const char *small){
  
   int len1 = strlen(big);
   int len2 = strlen(small);
   int i, j;
   for (i = 0; i <=len1-len2; i++)
    {
        for (j = 0; j < len2; j++)
        {
            if (big[j+i] != small[j])
               break;
        }
        if(j==len2) // finded substring
           return 1;
    }
  
    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