Here is what I have to write:
A file called test_file contains an unknown number of lines of text. Write a complete program that reads in the file line-by-line and displays each line with a line number preceding it. For example,
test_file:
blah blah blah blah
yadda yadda yadda
and so on and so forth
the end.
output:
1 blah blah blah
2 yadda yadda yadda
3 and so on and so forth
4 the end.
What sort of gets me is how I could go about getting it to just count lines? I learned how to do words and characters, but not lines that I can recall. Could anyone provide an excerpt of code on how to do this? It would be much appreciated. Thanks.
A file called test_file contains an unknown number of lines of text. Write a complete program that reads in the file line-by-line and displays each line with a line number preceding it. For example,
test_file:
blah blah blah blah
yadda yadda yadda
and so on and so forth
the end.
output:
1 blah blah blah
2 yadda yadda yadda
3 and so on and so forth
4 the end.
What sort of gets me is how I could go about getting it to just count lines? I learned how to do words and characters, but not lines that I can recall. Could anyone provide an excerpt of code on how to do this? It would be much appreciated. Thanks.