Here is the assignment i havent gotten to the puttin stuff in the stat txt i am just focused on makin output right.
Design and implement a Visual C++ .NET program that numbers the lines of a text file and keeps some statistics about the text file. Your program should read lines of text from the file source.txt and output each line to the screen and to the file output.txt. Each line of output should be preceded by a line number. Print the line number at the beginning of the line, right justified in a field of three spaces. Follow the line number by a colon, then one space, then the line of text. You should remove any spaces at the beginning of a line (hint: read the input file one character at a time using <your_ifstream>.get(ch) and use <your_ifstream>.putback(ch)). Lines that are longer than 50 characters should be broken into multiple lines. Once you reach 50 characters in a line, insert a newline at the end of the current word (as soon as you read a space). This new line should not get a line number, but should be indented properly. Your program should also keep the following statistics about the text file: the number of lines, the number of words (assume words are separated by spaces and newlines, in other words, punctuation is part of the word), The length of the longest word and the length of the shortest word. These statistics should be output to the file stats.txt.
And here is the code:
Code:
int main ()
{
char i;
int count=1, c=0;
ifstream input;
ofstream stats;
ofstream output;
input.open("source.txt");
output.open("output.txt");
stats.open("stats.txt");
// yet to figure out how to loop it right
//so it stops after reading entire txt file so i did the count for now
while (count < 5)
{
input.get(i);
if (c < 1)
{
cout << " " << count << ": " << i;
output << " " << count << ": " << i;
}
if (c >>1)
{
cout << i;
output << i;
}
do
{
if ( c == 50)
{
cout << '\n' << " " << i;
output << '\n' << " " << i;
}
cout << i;
output << i;
}while (c >= 50 & i != '\n');
c = c + 1;
if (i == '\n')
{
count = count + 1;
c = 0;
}
}
return 0;
}
edit: it goes to an infinite loop when reaching the do-while loop