0

Find Longest and Shortest Line

I want to make a program that reads a file line by line and find the Line with the most amount of characters and the Line with the least amount of characters (Longest and Shortest Line) and the line number they are on, I've been stuck on this for a while.

31st May 2020, 3:27 PM
Jergan Hector
Jergan Hector - avatar
3 Réponses
0
Perhaps if you post a link to your code here, people might be more eager to help on the particulars.
31st May 2020, 3:31 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
0
here is what I have so far void Longest() { ifstream ptr; ptr.open("philosophy.txt"); string line; while (getline(ptr,line)) { for(int i = 0; line[i] !=' '; i++) { Count++; } } } I also tried this void Longest() { ifstream ptr; int tmp; ptr.open("philosophy.txt"); string line; while (getline(ptr,line)) { tmp=line.size(); cout<<tmp; } } but they both dont output anything
31st May 2020, 3:42 PM
Jergan Hector
Jergan Hector - avatar
0
okay after long research and getting some help from a friend I have gotten to this point but the output is incorrect https://code.sololearn.com/cf4aw5EI41Db it outputs -2 as the shortest line and 0 as the number of characters on the line
31st May 2020, 6:23 PM
Jergan Hector
Jergan Hector - avatar