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.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -