I have a text file with some information that i need to format and withdraw in the same text file but with extension out. Only criteria of formatting is to have maximum 80 symbols in every row. I thought that it might be realised by creating a counter that will read words from text and by the last symbol of every word will start counting till 80. Thus,if the count reach 80 it moves the text and the word that exceeded the limit to the next row and the counter is reset to zero . Unfortunaly , i'm still at "baby steps" in programming so i don't know how to make it or if it is even the right approach for the problem . Can you help me?
Any other ideas or ways to do it are welcomed. That's the code i have :
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
string line;
int sum=0;
ifstream inData ;
inData.open("input.txt");
ofstream outFile("output.txt");
while(!inData.eof())
{
getline(inData,line);
int numofChars= line.length();
for (unsigned int n = 0; n<line.length();n++)
{
if (line.at(n) == ' ')
{
numofChars--;
}
}
sum=numofChars+sum;
}
outFile << sum << endl;
return 0 ;
}
It's counting the characters in the text file but i can't get how to make it if the count reaches 80 text gets to the next row and counting starts again