c使用va_list打印参数列表

| 我有一个简单的参数列表。而且我只是想将其打印到标准输出,但是在打印“结束”之前我要获得有线输出。有谁知道空行和不可读字符来自何处? 输出:
start
hello
hello2
hello3
hello 4

UH��AWAVAUATE1�S1�H��HH�E�
end



void printTest(const char* msg, ...) {

    va_list ap;
    int i;
    const char* curMsg=0;
    va_start(ap, msg);
    printf(\"start\\n\");

    for(curMsg= msg ;  curMsg!=0 ; curMsg = va_arg(ap,  const char*)){
        printf(\"%s\\n\", curMsg);
    }
    printf(\"end\\n\");
    va_end(ap);
}



int main(){

    printTest(\"hello\", \"hello2\", \"hello3\", \"hello 4\");
    return 0;
}
    
已邀请:
        当您未传递空指针时,您如何期望读取空指针来终止循环?将呼叫更改为:
printTest(\"hello\", \"hello2\", \"hello3\", \"hello 4\", (char *)0);
    
        va_list列表不是以NULL结尾的。实际上,它不提供有关有多少个参数的任何信息。您的论点必须表明存在多少个论点。例如,对于printf(),format参数指示要处理的其他参数的数量。 如果您需要列表以NULL结尾,则需要传递NULL作为最后一个参数。     

要回复问题请先登录注册