I wrote a recursive function in C to undo an integer (123 → 321), which worked fine when I ran it on my Mac, but behaved strangely when my instructor ran it on my Windows machine.
int rev(int num)
{
int base;
if (num < 10) return (num);
base = pow(10,(int)log10(num));
return(rev(num/10)+num%10*base);
}
For example, when calling OSX rev (8765), 5678 returns, in Windows rev (8765) returns 5672. I don’t have access to the Windows machine to try to run the program in debug mode, so I could hardly guess what the problem was. I would really appreciate your understanding!
Wednesday:
I am using OSX 10.8 and GCC 4.2. I am pretty sure that my instructor uses MinGW as his compiler.
source
share