LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] OT: max function

[ILUG] OT: max function

Caolan McNamara cmc at stardivision.de
Mon May 22 13:33:40 IST 2000


>>>>>>>>>>>>>>>>>> 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.





More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


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!
RSS Version
Powered by Dell