Question

In: Computer Science

how to code the text with excess whitespace removed in C++. Whitespace includes spaces and tabs....

how to code the text with excess whitespace removed in C++. Whitespace includes spaces and tabs. Excess whitespace is:

• All whitespace at the beginning of the text.

• All whitespace at the end of the text.

• Any point in the text where more than a single whitespace character is used.

For instance, if the input text is: Welcome to C++ !

The output would be: Welcome to C++!

Solutions

Expert Solution

Sample output:

The screenshots are attached below for reference.

Please follow them for proper indentation and output.

Program to copy:

#include <iostream>
#include<string>
using namespace std;

int main()
{
char str[100]={0};
  
cout<<"Enter text:";
cin.getline(str,100);//read input from user
int i=0;
int k=0;
int space=0;
while(str[i]!='\0'){//loop till end of input
while(k==0 && str[i]==' ')//removinf spaces if oresent in beginning
i++;
  
if(str[i]==' ')//if space occurs check for previous character
{
if(space==0){
str[k]=str[i];
k++;
space=1;
}
}
  
else if(str[i]=='!'){//check punctuation caracters
if(str[k-1]==' '){
str[k-1]=str[i];
}
else{
str[k]=str[i];
k++;
}
space=0;
}
else{
str[k]=str[i];
k++;
space=0;
}
i+=1;
}
str[k]='\0';//end the string
i=0;
while(str[i]!='\0'){//print the result string
cout<<str[i];
i++;
}
return 0;
}


Related Solutions

1) How do you read the contents of a text file that contains whitespace characters as...
1) How do you read the contents of a text file that contains whitespace characters as part of its data? 2) What capability does the fstream data type provide that the ifstream and ofstream data types do not? 3) What header file do you need to include in a program that performs file operations? 4) What data type do you use when you want to create a file stream object that can write data to a file? 5) What data...
3. How are the excess starting materials removed from the alum product? 4. What is the...
3. How are the excess starting materials removed from the alum product? 4. What is the purpose of using isopropyl alcohol in this experiment? 5. During the washing step, how can you tell when your product has been sufficiently purified?
Using C++, write a code that this program always stores text file output into a text...
Using C++, write a code that this program always stores text file output into a text file named "clean.txt". -The program should read one character at a time from "someNumbers.txt", and do the following. -If it is a letter, print that letter to the screen, AND also store it in the text file. All letters should be converted to lowercase beforehand. -If it is a number, print that number to screen, but do NOT store it in the text file....
C Programing How would i edit this code to have it return the cipher text. void...
C Programing How would i edit this code to have it return the cipher text. void vigenereCipher(char* plainText, char* k){ int i; char cipher; int cipherValue; int len = strlen(k); //Loop through the length of the plain text string for(i=0; i<strlen(plainText); i++){ //if the character is lowercase, where range is [97 -122] if(islower(plainText[i])) { cipherValue = ( (int)plainText[i]-97 + (int)tolower(k[i % len])-97 ) % 26 +97; cipher = (char)cipherValue; } else // Else it's upper case, where letter range is...
Write the following assembly code file into C code. .globl main .text main:    # Tests...
Write the following assembly code file into C code. .globl main .text main:    # Tests simple looping behaviour    li t0, 60    li t1, 0 loop:    addi t1, t1, 5    addi t0, t0, -1    bne t1, t0, loop    bne t1, zero, success failure:    li a0, 0    li a7, 93 # a7 is what determines which system call we are calling and we what to call write (64)     ecall # actually issue...
Create C# code that can search a text file and output the data at the line...
Create C# code that can search a text file and output the data at the line number inputted and amount of entries needed. Example of call in command window: Search16s filename.txt 273   10 Where 273 is the line number to start the output from, and 10 is the number of sequences that the program should output. The number of sequences entered on call should always be a odd number or give an error in console. The output should also display...
Write a c or matlab text code(to be copied ) for Huffman coder and Huffman decoder...
Write a c or matlab text code(to be copied ) for Huffman coder and Huffman decoder that asks the user to enter the string and output the Huffman code for every letter and a code for encoding that will have every letter and its Huffman code and output all the possibilities for the real string. you must show a screen of an input and the output for both the encoder and the decoder
Write a C++ program using produces Huffman code for a string of text entered by the...
Write a C++ program using produces Huffman code for a string of text entered by the user. Must accept all ASCII characters.
C++ Code You will write a program to process the lines in a text file using...
C++ Code You will write a program to process the lines in a text file using a linked list and shared pointers. You will create a class “Node” with the following private data attributes: • Line – line from a file (string) • Next (shared pointer to a Node) Put your class definition in a header file and the implementation of the methods in a .cpp file. The header file will be included in your project. If you follow the...
Write a C++ program using produces Huffman code for a string of text entered by the...
Write a C++ program using produces Huffman code for a string of text entered by the user. The string given by the user can be either 1 word or 1000 words. Must accept all ASCII characters. Please do not copy from the internet. This is my 3rd time posting the same question and I have not received a correct answer.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT