可变函数中的冲突类型

A23*_*A23 -2 c variadic-functions

经过很长一段时间的项目后,我再次与C合作,并试图了解可变功能.基本上,我希望能够将多个字符串传递给函数.

#include<stdarg.h>

int main(int argc, const char * argv[])
{

    test_function(2,"test","test2");
    test_function(4,"test3","test4","test5","test6");

    return 0;
}


void test_function(int args, ...)
{
    va_list ap;
    va_start(ap, args);

    int i;
    for(i=0;i<args;i++)
    {
        printf("Argument:%s\n",va_arg(ap, char*));
    }

    va_end(ap);
}
Run Code Online (Sandbox Code Playgroud)

我在test_function周围出现错误 - 'test_function'的冲突类型

谁能指出我的错误?

Yu *_*Hao 8

test_function在使用它之前说出声明.stdio.h因为您正在使用,您还需要包括在内printf.

#include <stdarg.h>
#include <stdio.h>

void test_function(int args, ...);

int main(int argc, char * argv[])
{
Run Code Online (Sandbox Code Playgroud)