Count the number of lines in a file - C -
i'm receiving input file, bunch of lines. want able count lines analyse them.
the input many lines of code integers. ex:
3 2 1 2 2 3 4 3 1 2 2 3 3 4
here's tricky part: first line has 2 numbers: 3 , 2. (the 3 isn't relevant now). 2 important. represents number of lines have read , save. so, according example have save lines
1 2 2 3
so why there other lines? - ask. well, let's see input blocks. after line 3 2
read 2 lines. it's block ended. then, line 4 3
came along. means have exact same thing did first block. so, line 4 3
know have read , save next 3 lines. meaning lines
1 2 2 3 3 4
i've been head on hills , can't seem find possible solution
when you've got problem this, it's useful think of structure first. here's 1 method in simple pseudocode main algorithm started. people can't unless present code , problem it.
declare line buffer array while (read line buffer == succeeds) { scan buffer 2 numbers (m, n) loop how many times? { read line buffer scan buffer next 2 numbers (x, y) } }
that shouldn't difficult translate c. can expand store numbers you've scanned, count lines, or whatever else.
once you've got code, if doesn't work , can't figure out what's going wrong, you'll plenty of help.
Comments
Post a Comment