Saturday, May 26, 2007

cpp tips-2

Access variable-argument lists.
-----------------------------------------


Required header file : "stdio.h" and "stdarg.h"

#include "stdarg.h"
int average( int first, ... );




int main( void )
{

/* Call with 3 integers (-1 is used as terminator). */
printf( "Average is: %d\n", average( 2, 3, 4, -1 ) );

/* Call with 4 integers. */
printf( "Average is: %d\n", average( 5, 7, 9, 11, -1 ) );

/* Call with just -1 terminator. */
printf( "Average is: %d\n", average( -1 ) );
}


int average( int first, ... )
{
int count = 0, sum = 0, i = first;
va_list marker;

va_start( marker, first ); /* Initialize variable arguments. */
while( i != -1 )
{
sum += i;
count++;
i = va_arg( marker, int);
}
va_end( marker ); /* Reset variable arguments. */
return( sum ? (sum / count) : 0 );
}


char array pointer :
-------------------------

Is it possible to use ?

void Display(char szText[100])
{
printf("%s",szText);
}

yes, the above code is working well.
we can display the unicode characters using wcout stream like cout stream.


Is there any class or stream available for logging information in C++?

yes ... clog stream can be used for logging purpose.


Is there any c++ function available for converting ANSI to unicode and unicode to ANSI conversion ?


yes...

wcstombs()-Convert sequence of wide characters to corresponding sequence of multibyte characters.
mbstowcs()- Convert sequence of multibyte characters to corresponding sequence of wide characters.



Is there any functions to convert the unicode characters to long or double like that ?...

yes, Required headers are or .

wcstol () - converts wchar* to long
wcstod() - converts wchar* to double
wcstoul() - converts wchar* to unsigned long

Labels:

0 Comments:

Post a Comment

<< Home