Hi everyone,
Here is my problem:
For my research I need to work with files of 700 Mb. I get "Segmentation Fault" error and while my code works for smaller files, I assumed the large size of the file leads to this problem. That is why I think that I need to split the files into smaller ones.
A simplified version of a sample file looks like:
[TEX]
Line #
1 Day 1 Month 1 1
2 Day 2 Month 2 1
3 Day 3 Month 3 1
4 Day 4 Month 4 1
5 Day 5 Month 5 1
6 Day 6 Month 6 1
7 Day 7 Month 7 1
8 Day 8 Month 8 1
9 Day 9 Month 9 1
10 Day 10 Month 10 1
11 Day 11 Month 11 1
12 Day 12 Month 12 1
13 Day 1 Month 1 2
14 Day 2 Month 2 2
15 Day 3 Month 3 2
16 Day 4 Month 4 2
17 Day 5 Month 5 2
18 Day 6 Month 6 2
19 Day 7 Month 7 2
20 Day 8 Month 8 2
21 Day 9 Month 9 2
22 Day 1 Month 10 3
[/TEX]

I want to store data related to each number in a separate file. In other words I want to collect data in line 1 to 12 into one file, and from 13 to 21 in another and so on. I am ale to find the line numbers where the file needs to be cut. But I do not know where to go from there. I would appreciate any suggestion.

Open the input file
Open the first output file
Read a line
Count it
Write the line
Read a line
Count it
Write the line
Read a line
Count it
Write the line
-- when the count gets to one of your magic numbers
Close the output file
Open the next output file
Continue reading, counting, writing...

Thanks a lot. I have got my code working using your suggestion.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.