【发布时间】:2011-06-15 05:26:42
【问题描述】:
我有一个简单的参数列表。我只想将它打印到标准输出,但在打印“结束”之前我得到了有线输出。有谁知道那个空行和不可读的字符是从哪里来的??
输出:
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;
}
【问题讨论】:
标签: c printf variadic-functions