- #1
ghost305
- 14
- 0
I'm having problem with a program I am trying to write that reads a .text sourcefile and then format the .text file while removing excess whitespace.
I'm having issues formatting the input stream text file(removing excess whitespace.
Demo text:
The
kid is
playing in the field
because he doesn't want to go inside.
Output text(supposed to look like).
It should look like this:
The kid is playing in the field because he doesn't want to go inside.
Code:
#include <fstream>
using std::ofstream;
using std::ifstream;
#include <iostream>
using std::cin;
using std::cout;
using std::cerr;
#include <sstream>
#include <iomanip>
#include <cstring>
using std::string;
using namespace std;
#include <cstdlib>
using std::exit;
#include <stdio.h>
int main (void)
{
const int MAX = 100;
char buff[MAX];
string name;
int i;
int countWords(const char string[]);
void readLine(char buffer[]);
cout << "Enter name of input text file(location on disk): "<<endl;
getline (cin, name); //Prompts user to input source text
ifstream input; //create stream object homework
input.open ( name.c_str() ); //reads source text file
if (!input) {
cerr << "Unable to open file hw6.txt";
exit(1); } // call system to stop
else{
while (!input.eof()) //until end of file
{
input.getline(buff, MAX); //read line of text
cout << buff << endl;
} //display text(pre-formatted)
}
cout << "Enter name of the output text file: " <<endl;
getline (cin, name); //Promt user to input output text
ofstream output; //create stream object homework2
output.open (name.c_str() );
if(!output){
cerr << "Unable to create text file\n";
exit(1);} //call system to stop
}
Demo text:
The
kid is
playing in the field
because he doesn't want to go inside.
Output text(supposed to look like).
It should look like this:
The kid is playing in the field because he doesn't want to go inside.