G
gaoqiang
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int ssnprintf(char**arg,size_t n,const char*format,va_list va)
{
size_t len=snprintf(NULL,0,format,va);
len+=1;
if(len>n){
free(*arg);
*arg=malloc(len);
}
snprintf(*arg,len,format,va);
return 0;
}
int main()
{
char*p=NULL;
ssnprintf(&p,4,"abcdefgh%d",3);
printf("p= %s\n",p);
free(p);
return 0;
}
compile this program with gcc,I got
a.c:18: warning: passing argument 4 of 'ssnprintf' makes pointer from
integer without a cast
to say this line:
ssnprintf(&p,4,"abcdefgh%d",3);
then how to eliminate this warning ?
#include <stdlib.h>
#include <stdarg.h>
int ssnprintf(char**arg,size_t n,const char*format,va_list va)
{
size_t len=snprintf(NULL,0,format,va);
len+=1;
if(len>n){
free(*arg);
*arg=malloc(len);
}
snprintf(*arg,len,format,va);
return 0;
}
int main()
{
char*p=NULL;
ssnprintf(&p,4,"abcdefgh%d",3);
printf("p= %s\n",p);
free(p);
return 0;
}
compile this program with gcc,I got
a.c:18: warning: passing argument 4 of 'ssnprintf' makes pointer from
integer without a cast
to say this line:
ssnprintf(&p,4,"abcdefgh%d",3);
then how to eliminate this warning ?