c - Using the return value of "scanf()" to check for end of file -
i searching net on how use return value of scanf check end of file! found following code.but having difficulty in understanding?
how method working?
what '~' operator signify?
while(~scanf("%d",&n)) { /* solution */ }
this horrible way check if value different -1. ~x
returns bitwise negation of x
. having in mind complimentary code used negative numbers(on most compilers way approach not portable) -1 represented sequence of 1-s , ~(-1)
produce zero.
please don't use approach. write scanf("%d", &n) != eof
way easier understand.