[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]
Re: function arguments
Hi deepak,
you can try the implementation of printf for your problem
here is a sample program which shows you the variable argument
implementation
forgive me for my bad programming style but here it is anyway...
this is just an excert from my sample programs i had written when i was a
stiudent
void main( void )
{
int y,p,q,r,s,t;
printf( "Average is: %d\n", average(10,y,p,q,r,s,t) );
}
/*
int average(int cc,int first ... )
{
cout << cc << endl;
int count = 0, sum = 0;
void *i ;
va_list marker;
va_start( marker, first );
// intvec.push_back(&first);
i = new int(10);
while( first > 0 )
count++;
*(int *)i = (int)va_arg( marker, int);
int *x = new int;
*x = *(int *)i;
intvec.push_back(x);
( first)--;
}
va_end( marker );
for(count=0,iter = intvec.begin(); iter!= intvec.end() ; iter++)
cout << (*(int *)(*iter)) << endl;
return 1;
}
regards
mahesh
- mahesh@xxxxxxx
----- Original Message -----
From: deepak yadav <deepak2000@xxxxxxxxxxxx>
To: linux-india-programmers <linux-india-programmers@xxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, June 30, 2000 11:22 AM
Subject: [LIP] function arguments
> hi
> i posted this problem earlier but i am not receiving any mails from LIP.
please help me out.
>
> i have to print some values. i don't know before hand what is their type
and number which can only be determined when it is run.
> i want to do something like
>
> for(i = 0; i < num ; i++ ) {
> str = getFormatSpecifierString(i);
> printf(str, value[i]);
> }
>
> is such thing possible. what kind of array 'value' be.
>
> thanks
>
> -----------------------------
> reply soon
> bye
>
> __ deepak __
>
> have a great day
> ICQ 30662394
> -
> -
>
> This screen intentionally left blank.
>
>
> -----------------------------------------------------------------------
> For more information on the LIP mailing list see:
> http://lists.linux-india.org/lists/LIP
>