I am getting an incredibly weird bug in my C program in a UNIX environment. I wonder if anybody could take a crack at this.
Real quick summary, my program takes command line arguments, I'll focus on a particular case. The following command line execution of the program should read input from input.txt and output it to output.txt
Code:
./program -f output.txt input.txt
If a line starts with "#include <someFileName>", the contents of that file is printed to output.txt instead of that line. This is handled recursively by my program. I create a new file stream to that file and send the FILE * to the same printing function. This works perfectly fine except for my really odd case.
Really odd bug:
Let's assume the command line execution above is used. If input.txt contains "#include <output.txt>", it works. I do flush the buffer before recursively printing the #include file. However, this breaks as soon the input file has more than seven "#include <output.txt>" lines in it. Seven or less works fine. Anything more causes a crazy infinite loop that causes output.txt to bloat to a 100+ MB file. I also tried this on my university's Linux box. It will allow up to 15 of these #include statements, but 16 or more gives the same bug. I cannot appropriately evoke EOF with ctrl + D either. I have to kill the execution with ctrl + C. My recursion is not going too deep to cause any issues either. It's only 1 level deep of recursion. The first block of code works fine, the second block breaks it.
This input.txt won't cause problems:
Code:
One
Two
#include <output.txt> 1
#include <output.txt> 2
#include <output.txt> 3
#include <output.txt> 4
#include <output.txt> 5
#include <output.txt> 6
#include <output.txt> 7
This input.txt will cause problems:
Code:
One
Two
#include <output.txt> 1
#include <output.txt> 2
#include <output.txt> 3
#include <output.txt> 4
#include <output.txt> 5
#include <output.txt> 6
#include <output.txt> 7
#include <output.txt> 8
I'm not really sure about the rules on sharing code that is an assignment. Anybody have experience of that being an issue? I'm not sure how much help could be given without showing the whole source file.