Ich habe leider im Netzt nichts gefunden.
Wie mache Ich Funktionen, denen Ich beliebig viele Parameter übergeben kann?
(Zum beispiel wie bei printf...)
Vielen Dank im Vorraus
Don Philippe
Funktionen mit beliebig vielen Parametern: Wie?
-
- Posts: 8
- Joined: 14. May 2004 14:38
Deklaration:
Die Punkte lassen beliebig viele Parameter zu. Wie man darauf zugreift steht inclusive Beispiel in der Manpage va_arg
Code: Select all
typ bezeichner(typ var1, typ var2, ...);
Hier ist ein Beispiel
int pvPrintf(PARAM *p, int id, const char *format, ...)
{
char text[MAX_PRINTF_LENGTH+40];
va_list ap;
va_start(ap,format);
#ifdef _WIN32
_vsnprintf(text, MAX_PRINTF_LENGTH - 1, format, ap);
#endif
#ifdef __VMS
vsprintf(text, format, ap);
#endif
#ifdef unix
vsnprintf(text, MAX_PRINTF_LENGTH - 1, format, ap);
#endif
va_end(ap);
pvSetText(p,id,text);
return 0;
}
{
char text[MAX_PRINTF_LENGTH+40];
va_list ap;
va_start(ap,format);
#ifdef _WIN32
_vsnprintf(text, MAX_PRINTF_LENGTH - 1, format, ap);
#endif
#ifdef __VMS
vsprintf(text, format, ap);
#endif
#ifdef unix
vsnprintf(text, MAX_PRINTF_LENGTH - 1, format, ap);
#endif
va_end(ap);
pvSetText(p,id,text);
return 0;
}
tach
Hier gibts ein Tutorial dazu:
http://pronix.de/modules/C/openbook/c_p ... ung_21.php
greetz by
squeez
Hier gibts ein Tutorial dazu:
http://pronix.de/modules/C/openbook/c_p ... ung_21.php
greetz by
squeez