Create a function removeWhite(const char *str1, char *str2) that removes all spa
ID: 3687209 • Letter: C
Question
Create a function removeWhite(const char *str1, char *str2) that removes all spaces inside strl 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 remove White 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
Program:
// simple logic in C programming
#include<stdio.h>
void main()
{
char str[30];
char str1[30];
int i,j=0;
puts("plz enter string:");
gets(str);
for(i=0;str[i]!=NULL;i++)
{
if(str[i]!=' ')
str1[j++]=str[i];
}
str1[j]='';
puts(str1);
}
or
/*
* C Program to remove extra spaces
*/
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main(){
char inputString[100], outputArray[100];
int readIndex = 0, writeIndex;
printf("Enter a String ");
gets(inputString);
/* Skips all spaces before first characters */
while(inputString[readIndex] == ' '){
readIndex++;
}
for(writeIndex = 0;inputString[readIndex] != ''; readIndex++){
if(inputString[readIndex]==' ' && inputString[readIndex-1]==' '){
continue;
}
outputArray[writeIndex] = inputString[readIndex];
writeIndex++;
}
outputArray[writeIndex] = '';
printf("String without extra spaces %s", outputArray);
getch();
return 0;
}
final program:
Here is C source code for replacing the character from string. The output of this program shown below.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.