C++ coding problem

Hi Everyone,
My name is Hitesh Khurana, let me get straight to the point.
I am working on homework for my programming class;however, I keep running into a problem when running my program.
The problem given to the students as the assignment is:
We need to create a program that reads a text file and counts the characters in each line. The program should display the line number and the length of the shortest and longest lines in the file, as well as the average number of characters per line.
Now here is what my problem is.
When I run my program what happens is, that it keeps running. i have tried several compilers and it just never stops looking inside a 3 character text file
(for test purposes). Here is the code feel free to correct any problem that I may have , but please reply ASAP.
NOTE: I have copied this code from the textbook just to see troubleshoot my coding. Now when you compile this the textfile I use is called test.txt
it contains 3 characters 'thi' (without the single quotes) and is located in the same directory as the cpp code the program just keeps running, it is really frustrating lol.
Solved so removed for stopping plagirism reasons ;)
P.S. I have searched on google but no help :(. If you would like to know the textbook the isbn is 0131409093.
Last edited on
This program computes the number, maximum, minimum..
You need to have numbers in your text file, not characters.
Thank you for your reply, it actually is supposed to count the number of characters in a line
I think when you try putting integers in your text file it will work correctly.
It's supposed to hold characters not integers, if what you're saying is true then how can i make switch the reading from integers to amount of characters?
reading is of type double. You're trying to read letters into a variable of type double. This puts the input stream (fin in this case) into a fail state. Since you don't check the state of the stream other than whether it's hit eof, your loop never exits.
Thank you so I have to change reading to a char but then how would I get the amount of characters in the line? and didn't I check for eof here:
solved stopping plagirism ;)
Last edited on
Thanks guys I got it working to where it can count characters but how can i make it count the line number and the shortest and longest lines?
Update:
Finally Completed the Program.
Thanks to everyone that helped I really appreciate it.
Last edited on
Topic archived. No new replies allowed.