Untitled
By: a guest | Mar 18th, 2010 | Syntax:
None | Size: 1.58 KB | Hits: 32 | Expires: Never
#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>
using namespace std;
string readLine(istream& fin)
{
char buff[256];
// Clear any remaining end of line characters
if(fin.peek()=='\n')
{
fin.ignore();
}
// Read the line into a buffer
fin.getline(buff, 256, '\n');
// Convert the buffer to a string and return it
return string(buff);
}
void main()
{
//variables
char ch;
int letters = 0;
int wordcount =0;
//input of words
//conversion of text file
//removal of capitals and punct
//struct
//word length count [12]
//
int wordlengthcount[12];
string word;
bool eofReached = false;
string fName = "initialattempt.txt";
string fName2 = "converted.ptx";
ifstream inFile(fName.c_str());
ofstream outFile("converted.ptx");
if(!inFile)
{
// If file is not read: Show error message
cout << "Error, can't open file" << endl;
}
else
{
// If file is read: Continue
while(!inFile.eof())
{
inFile >> word;
for(int i = 0; i < (int)word.length(); i++)
{
word[i] = tolower(word[i]);
if(ispunct (word[i]))
{
word[i] = ' ';
}
}
outFile << word << endl;
eofReached = inFile.eof();
}
inFile.close();
outFile.close();
}
ifstream ptxFile(fName2.c_str());
if(!ptxFile)
{ //////////////////////////////////////////////
/// If file is not read: Show error message///
//////////////////////////////////////////////
cout << "Error, can't open file" << endl;
}
else
{
while(!ptxFile.eof())
{
ptxFile>>word;
if(word.length()>12)
{
wordlengthcount[12]++;
}
else
{
wordlengthcount[word.length()-1]++;
}
}
}