]int input, frequency[9];
]
]//frequency[] initialised to 0.
]
]do {
] scanf("%d", &input);
] if (input > 0 && input < 11) {
] //point 1
] (frequency[input-1])++;
] //point 2
] }
] } while (input);
Hmmm. int frequency[9]; give you elements 0 -> 8 inclusive. If input=10,
then you are trying to access frequency[10-1], or frequency[9], which is not
part of your array. What seems to be happening is that 'input' is being
places in memory where frequency[9] would be, if it existed. Hence,
'frequency[9]++' is basically being a 'input++', in this case.
Please note that by accessing an array out of bounds, you are in unknown
territory. Different compilers, and different options, will do things
differently. There is generally no way to know what you might be accessing.
Gary
**********************************************************************
This e-mail and any attachment contains information which is private
and confidential and is intended for the addressee only.
If you are not an addressee, you are not authorised to read, copy or
use the e-mail or any attachment.
If you have received this e-mail in error, please notify the sender
by return e-mail and then destroy it.
**********************************************************************
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!