
April 5th, 2003, 08:10 PM
|
|
Contributing User
|
|
Join Date: Oct 2002
Posts: 61
Time spent in forums: 9 m 2 sec
Reputation Power: 11
|
|
|
getchar() and array
Hi,
Can anyone tell me why I have to use method1 (below) instead of method2 (below)?
method1::
.....
int c;
int digits[10];
.....
while ((c=getchar())!=EOF) {
if (c>='0' && c<='9') {
digits[c-'0']=digits[c-'0']+1;
}
}
.......
method2:
......
int c;
int digits[10];
.....
while ((c=getchar())!=EOF) {
if (c>='0' && c<='9') {
digits[c]=digits[c]+1;
}
}
......
Thanks in advance!
p/s: this program is used to count the occurances of its digits from 0 to 9.
Last edited by Alianto : April 5th, 2003 at 08:15 PM.
|