S
scigeek
Hello All,
I am trying to write a c++ program for converting a certain data
format into another format. In the process, I have to open and close
multiple output files depending on a particular value in the input
file.
Here is a toy example of the input file:
14
5 33 0 0 45 47
5 41 1 1 46 49
5 39 1 1 25 47
6 14 1 1 33 39 41
4 16 2 1 32
3 17 2 2
7 93 3 3 47 46 49 87
4 49 3 3 32
explanation: the first line contains the number of nodes in a graph.
From second line onwards, we need to look at the 3rd entry of each
line: lets call it "iteration number". For each iteration number, we
need to open a file, write the data into the file, and when a new
iteration number is encountered, all the data is to be dumped into the
currently opened file, close it and then open another output file for
the new iteration number. So for this particular toy example, we need
to have 4 out put files; one for iteration number 0, one with
iteration number 1, for iteration number 2 and iteration number 3.
I am using ofstream object outStream for manipulating writing into
output files and ifp for reading input stream. I find that the program
aborts with a message " double free or corruption "
(the program compiles alright) after reading in the final line of the
file and nothing is being written in the 4th output file that I opened
(by the way the other files contain all the data in the proper format
and they are perfect, except the final file). While checking, I found
out, that after reading in the last of the line from the input file,
the ifp becomes 0 all of a certain and similarly the outStream object
shows a value of 0. It is confusing and with my moderate programing
ability, I couldn't figure out why this is happening.
I know it is difficult to say anything from this terse description of
my program. So if any body is interested to help me out I can send the
source code (with proper comments) to him/her.
It would be of immense help to me if I can get this program to run and
know where I am faulted. PLEASE NOT, IT IS NOT RELATED TO ANY
CLASSROOM WORK at all. It is a small part of my research project. If I
can run it, it would save me considerable time and effort for
otherwise, i have to run 200 iterations manually, corresponding to
each iteration number for each input file.
Thanks and regards,
I am trying to write a c++ program for converting a certain data
format into another format. In the process, I have to open and close
multiple output files depending on a particular value in the input
file.
Here is a toy example of the input file:
14
5 33 0 0 45 47
5 41 1 1 46 49
5 39 1 1 25 47
6 14 1 1 33 39 41
4 16 2 1 32
3 17 2 2
7 93 3 3 47 46 49 87
4 49 3 3 32
explanation: the first line contains the number of nodes in a graph.
From second line onwards, we need to look at the 3rd entry of each
line: lets call it "iteration number". For each iteration number, we
need to open a file, write the data into the file, and when a new
iteration number is encountered, all the data is to be dumped into the
currently opened file, close it and then open another output file for
the new iteration number. So for this particular toy example, we need
to have 4 out put files; one for iteration number 0, one with
iteration number 1, for iteration number 2 and iteration number 3.
I am using ofstream object outStream for manipulating writing into
output files and ifp for reading input stream. I find that the program
aborts with a message " double free or corruption "
(the program compiles alright) after reading in the final line of the
file and nothing is being written in the 4th output file that I opened
(by the way the other files contain all the data in the proper format
and they are perfect, except the final file). While checking, I found
out, that after reading in the last of the line from the input file,
the ifp becomes 0 all of a certain and similarly the outStream object
shows a value of 0. It is confusing and with my moderate programing
ability, I couldn't figure out why this is happening.
I know it is difficult to say anything from this terse description of
my program. So if any body is interested to help me out I can send the
source code (with proper comments) to him/her.
It would be of immense help to me if I can get this program to run and
know where I am faulted. PLEASE NOT, IT IS NOT RELATED TO ANY
CLASSROOM WORK at all. It is a small part of my research project. If I
can run it, it would save me considerable time and effort for
otherwise, i have to run 200 iterations manually, corresponding to
each iteration number for each input file.
Thanks and regards,