There can be problems with the standard libraries. I found that some functions behave differently from the Standard C. That can depend on the compiler.
I had this problem with the function pow in and I have defined a pow2 function that does not have the problem.
Another possibility is to have an header file SYS.h in the different operative systems
with only this line
#define UBUNTU 1
in UBUNTU or
#define SUNos 1
for the SUN and so on fon any different machine you use.
Then the OS dependent command shoul be written as
#include SYS.h
.......
#ifdef UBUNTU
ubuntu command
#endif
#ifdef SUNos
SUN command
#endif
...
In this way you can define OS specifi command.
Obviously you have to adapt the code before it is used on different OS.
I only wandering if you have checked the line termination in the data file.
In reading files, often the line ending char '\n' and '\r' are mixed in the different OS and sometime (windows) line is terminated with the \n\r or \r\n.