c出现Segmentation fault

来源:百度知道 编辑:UC知道 时间:2024/06/17 23:15:56
#include <stdio.h>
#include <stdarg.h>

void log(char *smg,...);
main()
{

int a=3,b=5;
log("the %d is %s and c is %s\n",a,"4",b);

}

void log(char *smg,...)
{
va_list arg;
char tmpbuf[100];
memset(tmpbuf,0x00,sizeof(tmpbuf));

va_start(arg,smg);
vsprintf(tmpbuf,smg,arg);
va_end(arg);
printf("the buf is [%s]\n",tmpbuf);
}

程序如上,请高手帮忙

那是因为你所写的程序有错
现在正确的程序如下
#include <stdio.h>
#include <stdarg.h>
#include <WINSOCK2.H>

void log(char *smg,...);
void main()
{
int a=3,b=5;
log("the %d is %s and c is %d\n",a,"4",b);
}

void log(char *smg,...)
{
va_list arg;
char tmpbuf[100];
memset(tmpbuf,0x00,sizeof(tmpbuf));

va_start(arg,smg);
vsprintf(tmpbuf,smg,arg);
va_end(arg);
printf("the buf is [%s]\n",tmpbuf);
}
已经调试可以了,不知道是否是你要的结果。
祝你好运