How can I pass an array as parameters to a vararg function?

我的梦境 提交于 2019-12-01 03:29:22
ecatmur

There's no standard way to construct or manipulate va_args arguments, or even pass them to another function (Standard way to manipulate variadic arguments?, C Programming: Forward variable argument list). You'd be better off seeing if you can access the internal routines of LogEvent.

pass a pointer to the array of ints and a number of ints instead

#include <stdio.h>

void logevent(int n, int num, int *l) {
    int i;
    for (i=0; i<num; i++) {
        printf("%d %d\n",n,*(l++));
    }
    }

int main() {

    int activities[8];
    activities[0]=2;
    activities[1]=3;
    activities[2]=4;
    int num=3;
    int n=1;
    logevent(n,num, activities);
    printf("=========\n");
    n=2;
    activities[3]=5;
    num=4;
    logevent(n,num, activities);

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!