olivthill | Quel est ton système exploitation, quel est ton compilateur ?
Je ne trouve pas GETOpt sous Windows avec mon Borland C.
Si c'est pour manipuler des fonctions pouvant avoir plusieurs paramètres, il faut utiliser va_start, va_arg, et va_end. Par exemple :
Code :
- #include <stdio.h>
- #include <stdarg.h>
- /* calculate sum of a 0 terminated list */
- void sum(char *msg, ...)
- {
- int total = 0;
- va_list ap;
- int arg;
- va_start(ap, msg);
- while ((arg = va_arg(ap,int)) != 0) {
- total += arg;
- }
- printf(msg, total);
- va_end(ap);
- }
- int main(void) {
- sum("The total of 1+2+3+4 is %d\n", 1,2,3,4,0);
- return 0;
- }
|
Edit: Je me souviens maintenant que cela existe sous Unix. Par exemple :
Code :
- while( (c = getopt(argc, argv, "Ve:T:P:H:" )) != EOF )
- {
- switch(c)
- {
- case 'V' : vflag++ ; out++ ; break ;
- case 'e' : CB_Environ = optarg ; break ;
- case 'T' : tunes = optarg ; break ;
- case 'P' : strcpy( Input_Code, optarg );break;
- case 'H' : strcpy( Input_Time, optarg );break;
- case '?' : errflg++ ; out++ ; break ;
- }
- }
|
Message édité par olivthill le 29-10-2005 à 12:51:40
|