can i know what does it do actually
while (( c=getchar())!=EOF)
if ( c>= '0' && c <= '9')
++ndigit{c-'0'];
when ever i type the numerics into the arrays
it will enter into the ndigits
so what is exactly c-'0' here
can i know what does it do actually
while (( c=getchar())!=EOF)
if ( c>= '0' && c <= '9')
++ndigit{c-'0'];
when ever i type the numerics into the arrays
it will enter into the ndigits
so what is exactly c-'0' here
please use code tags. Read the sticky at the top of this forum. Otherwise your code is a mess and hard to understand.
can i know what does it do actually
while (( c=getchar())!=EOF)
if ( c >= '0' && c <= '9')
++ndigit [c-'0'];
when ever i type the numerics into the arrays
it will enter into the ndigits
so what is exactly [c-'0'] here
what i know is c is character entered through the console
and then what is happening next?
PLEASE READ THIS
http://cboard.cprogramming.com/showthread.php?t=25765
If you cannot be bothered to read the guidelines on posting code when asked to do so, then most people cannot be bothered to help you either. Also your code lacks formatting. Please remember this in future.
[c-'0'] is converting the ASCII character you typed into an integer value by subtracting the ASCII code for '0' from the character typed.Code:while (( c=getchar())!=EOF) if ( c >= '0' && c <= '9') ++ndigit [c-'0'];
Hope that helps.
If you still don't understand [c-0], this might be helpful to you.
>so what is exactly [c-'0'] here
Digits in C's standard character set are required to be contiguous in value. For example, in ASCII the digits 0 through 9 would be 48 through 57. What happens if you take the value of a digit, say '2' (50) and subtract '0' (48) from it? 50 - 48 == 2, so you get the numeric value that the character represents (2) instead of the underlying numeric value of the character (50).
My best code is written with the delete key.