I want to append data to files if a certain condition is true, else open a new file and keep writing to that file...this goes on in a loop.
This is what I am doing:
FILE* ptr
firstrun=1
***some code***
WHILE (condition)
{
if(!condition1 && !condition 2)
something
else if(condition1 || condition 2)
{
write data to file
if(firstrun)
FILE* ptr
fopen a file
firstrun=0
***some code***
if condition1
append data to previously opened file
if condition2
fclose
FILE* ptr
fopen another new file
}
}
The code as a whole doesn't seem to be working right but the other parts do seem right. The first file created matches the answer, but none of the following files do. I am also creating a whole lot more files, with no idea how much of the data is getting repeated.
Could anyone tell me whether what I have done here is right? I'm not posting the code because it's huge.
Some other cases:
1. If I don't declare FILE* ptr at the top, it doesn't compile because the only other declaration is inside an "if" condition
2. The other way is to use more "if"s which would make the code messier, and I'm not sure if that would work either.
Any help appreciated! Thanks!