- 论坛徽章:
- 0
|
菜鸟求救:在linux下用C语言实现参数个数可变得函数
#include<stdio.h>;
#include<string.h>;
#include<varargs.h>;
int demo();
void main(void)
{
demo("DEMO","this","is","a","demo!","\0" ;
}
int demo(char *msg, ...)
va_dcl
{
va_list argp;
int argno = 0;
char *para;
va_start(argp,msg);
while(1)
{
para = va_arg(argp,char*);
if(strcmp(para,"\0" == 0)
break;
printf("parameter #%d is:%s\n", argno, para);
argno++;
va_end(argp);
return 0;
}
}
gcc unix.c,报错:
unix.c: In function `main':
unix.c:6: warning: return type of `main' is not `int'
unix.c: At top level:
unix.c:10: conflicting types for `demo'
unix.c:10: a parameter list with an ellipsis can't match an empty parameter name list declaration
unix.c:4: previous declaration of `demo'
unix.c: In function `demo':
unix.c:10: parm types given both in parmlist and separately
unix.c:15:22: macro "va_start" passed 2 arguments, but takes just 1
unix.c:15: `va_start' undeclared (first use in this function)
unix.c:15: (Each undeclared identifier is reported only once
unix.c:15: for each function it appears in.) |
|