From: Caolan McNamara (cmc at domain stardivision.de)
Date: Mon 22 May 2000 - 13:33:40 IST
>>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<
On 22.05.00, 12:32:49, "John P. Looney (Kate)" <jplooney-ilug at domain 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.
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:06:14 GMT