4
Answers

Read data from a file and Write a set of X lines for Y times until end of data

Ask a question
C NewBee

C NewBee

12y
2.8k
1
I'm trying to read data from a file and write a set of x lines for y times until the end of the data file. For example:

This is my data file:
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
line 10
line 11
line 12
...

I want to read in line 1-9 and write this to a file 27 times, then read line 9-18 and write this to the same file for 27 times. My finished file should look something like:
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
...x27 times
line 10
...
line 18
...x27 times

My current code will write the first 9 lines for 27 times, but I'm not quite sure how to go about reading from 10-18 again. Please help! Any hint or suggestion is appreciated.


Attachment: program.zip

Answers (4)