The problem is you`re first locking all the pairs.
Take a look at this example:
0 0 1 1
1 0 0 1
0 (1) 0 1
0 0 0 0
In order to have no cycles the marked truth should not be considered but you already put that truth there when you locked all the pairs so now you can't see the free column because it`s not free anymore.
And at the end: if num of ...
Close, but no. The var file_name is a pointer that is set to null. No space is ever allocated to it using malloc. When the sprintf command tries to write the filename into it, it generates a seg fault.
There are two fixes here. You can malloc space to filename, or you can create a non-pointer string (char array) of sufficient length to hold the file names.
The problem is that you are decreasing the width. Instead of using width - 1, use width - j - 1. Eliminate the width--; line at the end of the inner loop. Also, instead of using j<width use j<(width/2).
Hope this helps. If it does then please check the tickmark.
You declare the variable counter outside of the loop, so it will retain its value and continuously increment over time.
The top left pixel at (0, 0) will have 3 neighbouring pixels, then next pixel at (0, 1) will have 5 neighbouring pixels. Consequently, counter will go from 3, to 8, and then scale beyond any of your test conditions that might print a result....
You have a problem with is_tie, your check value gets overwritten each time the loop goes. You should just return false when you know it isn't a tie and at the end return true if it it didn't end all ready .
fseek(inptr, -512, SEEK_CUR);
But why do you want to do this? There's no need in this program to manually move the pointer. What are you trying to do?
When you've read the 512 bytes into the header, they're available to both check for a signature and to write to the output file.
Being the loser of an already locked pair is not necessarily sufficient to create a cycle. If A beats B, and B beats C, there is no cycle, but your algorithm will not lock in B -> C if A -> B is already locked.