IT Community - Software Programming, Web Development and Technical Support

Elipsis Operator

This is a discussion on Elipsis Operator within the C and C++ Programming forums, part of the Software Development category; Hi all, What is elipsis operator in C and Can any one explain, at which situation we have to use ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C and C++ Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 08-11-2007, 08:41 AM
velhari velhari is offline
D-Web Programmer
 
Join Date: Mar 2007
Location: Chennai
Posts: 67
velhari is on a distinguished road
Send a message via AIM to velhari
Question Elipsis Operator

Hi all,
What is elipsis operator in C and Can any one explain, at which situation we have to use elipsis operator in C.
__________________
Regards,
VELHARI
I am not totally useless. I can be used for a bad example
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-23-2007, 04:24 AM
connect2sathya connect2sathya is offline
D-Web Trainee
 
Join Date: Feb 2007
Posts: 14
connect2sathya is on a distinguished road
Lightbulb Re: Elipsis Operator

using elipsis operator... u can pass any number of parameters ..... you can see this stdio.h file .... printf(), scanf () , functions uses this operator....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-24-2007, 02:37 AM
velhari velhari is offline
D-Web Programmer
 
Join Date: Mar 2007
Location: Chennai
Posts: 67
velhari is on a distinguished road
Send a message via AIM to velhari
Default Re: Elipsis Operator

Hi connect2Sathya,
Thanks for your reply.... i understood that we can pass as many no of argument to a function which uses elipsis operator.

So, i did my stuff here... but in this i have one problem
let me explain that problem with the following scenario..

I am using that elipsis operator to find out the greatest number.

Code:
#include <stdio.h>
void main()
{
        int greater;
        greater = find_greatest(5,1,9,2,7,4,6,1,0,18,59,37);
        printf("Greatest Number is %d",greater);
}
int find_greatest( val,...)
{
      //my stuff here
}
from here i got a problem. In that above said function find_greatest. I used the elipsis operator and passing multiple arguments from main.

In that function, for doing my stuff to calculate greatest no.. i have to know how many no of argument is passed from called function then only i have to start calculation for to finding the greatest no... for this how can i get the no of parameter is passed from the calling function and how to access that arguments in the calling function.....

Please help me to acheive this....
__________________
Regards,
VELHARI
I am not totally useless. I can be used for a bad example
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-23-2007, 06:45 AM
velhari velhari is offline
D-Web Programmer
 
Join Date: Mar 2007
Location: Chennai
Posts: 67
velhari is on a distinguished road
Send a message via AIM to velhari
Thumbs up Re: Elipsis Operator

Hi all,
Finally i found the solution for the above problem.
The following Macros are used for to get the argument values by using elipsis operator.

va_list
A Pointer Data Type
va_start()
A Macro Used to Initialize the argument list
va_arg()
A Macro Used to retreive each argument,in turn, from the variable list
va_end()
A Macro Used to “clean up” when all arguments have been retrieved


Code:
#include<stdio.h>
void main()
{
	int greater;
	greater = find_greatest(6, 1,2,50,35,12,90);
	printf("Greatest Number is %d", greater);
	getch();
}
int find_greatest(int num, ...)
{
	int vLoop=0;
	/* Declare a variable of type va_list. */
	va_list Args;
	/* Initialize the argument pointer. */
	va_start(Args, num);
	/* Retrieve each argument in the variable list. */
	Max = va_arg(Args, int);
	for ( vLoop=1; vLoop<num; vLoop++ )
	{
		Temp = va_arg(Args, int)
		if ( Max < Temp)
			Max = Temp;
	}
	/* Perform clean up. */
	va_end(Args);
	
	return Max;
}
__________________
Regards,
VELHARI
I am not totally useless. I can be used for a bad example

Last edited by velhari : 11-23-2007 at 06:49 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add two numbers without using addition operator Murali C and C++ Programming 0 10-31-2007 08:15 AM
sizeof() operator vigneshgets C and C++ Programming 2 09-11-2007 05:10 AM
overload subscript operator vigneshgets C and C++ Programming 0 08-14-2007 01:01 AM
Why is preincrement operator is faster than postincrement? prasath C and C++ Programming 1 07-30-2007 06:43 AM
Operator overloading in C++ prasath C and C++ Programming 1 07-16-2007 06:51 AM


All times are GMT -7. The time now is 01:50 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0