开发者

C: Comparing two long integers (very strange)

开发者 https://www.devze.com 2022-12-23 07:57 出处:网络
I have following situation (unix) : x is a long and has value 300 y is a long and has value 50000 if (x <= y) printf(\"Correct.\");

I have following situation (unix) :

x is a long and has value 300
y is a long and has value 50000

if (x <= y) printf("Correct.");
if (x > y) printf("Ouch.");

Now I always get "Ouch". That means the program keeps telling me that 300 is greater than 50000!

It only works again when I do

if ((int)x <=(int) y) printf("Correct.");
if ((int)x > (int开发者_开发技巧)y) printf("Ouch.");

So what is wrong with the comparison operators?


I found the error. It was using sscanf(...%d) instead of sscanf(...%ld). :( Thanks @ Zan Lynx for the hint and thanks to all of you!

0

精彩评论

暂无评论...
验证码 换一张
取 消