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

Write a C program that does the following: The program should get a phrase from

ID: 3832423 • Letter: W

Question

Write a C program that does the following: The program should get a phrase from the user (the phrase is composed of one or more words). The program should store the phrase in an array of suitable size. The program should the function squish and pass the input phrase to this function. This function squish should remove all spaces in the input phrase and return just the letters of the phrase (remember there may be leading and trailing spaces as well besides spaces between words). The main function should then print original phrase and the squished phrase.

Explanation / Answer

#include<stdio.h>

#include<conio.h>
// Function to remove all spaces in the inpur phrase
void squish(char *input)
{
int i, count = 0;

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

// main function
int main()
{
char input[50];
printf("Enter input phrase: ");
gets(input);
printf("original phrase: %s ", input);
squish(input);
printf("squished phrase: %s ", input);
return 0;
}

Output:-

Enter input phrase

this is the demo

original phrase: this is the demo

squished phrase: thisisthedemo

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