I have a program which processes thousands of chemical structures. To keep track of how many are being processed, and to avoid staring at a blinking cursor for minutes not knowing if anything is happening, I included a simple bit of code:

if((MOLNUMBER%10000)==0)
{
     fprintf(stderr,".");
}

What could possibly go wrong? Well when it reached entry 200999 it bombed out with a segmentation fault. Thinking it could be the structure there I cut it out and repeated it. This time it bombed out on entry 240999. These were suspiciously round numbers so I decided to cut out this bit of code and the program worked fine, albeit with just a blinking cursor. I'm curious to know why this might be. Haven't included any other code as I can't see how it could clash, unless anyone thinks differently. Why would this code cause a seg fault?

How is MOLNUMBER defined?

How is MOLNUMBER defined?

it is an integer (int MOLNUMBER;), which as a variable i use globally i put it in capitals (probably not good practice) I don't #define it as a constant. It is set after reading the molecule's entry number from the file.

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.