>>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<
On 22.05.00, 12:32:49, "John P. Looney (Kate)" <jplooney-ilug at online.ie>
wrote regarding Re: [ILUG] OT: max function:
> int arraymax(int *array, int arraysize)
> {
> int i;
> int max= (*array); //Max is first element in the array
> for(i=1;i<arraysize;i++) { //From the 2nd element, to the end
> if(*(array+i)<max) { //If what we are looking at is bigger than
max...
> max=*(array+i);
> }
> }
> }
"if(*(array+i)<max)"
What the!, if the contents of this array element is LESS than max !!,
you want if(*(array+i)>max)
and theres no need to go bezerk with the brackety pointer arithmetic,
square brackets are quite acceptable
int arraymax(int *array, int arraysize)
{
int i;
int max=array[0];
for(i=1;i<arraysize;i++)
if (array[i] > max)
max = array[i];
return max;
}
And while Im at it those look suspiciously like c++ comments in a C
program. Getting crotchety in my old age.
C.
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!