I'm having a problem with my program: I keep getting segmentation fault on a sprintf function and i can't get why,the buffer is large enough and i THINK to be passing the pointer correctly,i just can't figure out why it won't work.
Here's the code:
//same error with char *dataBuff=malloc(sizeof(char)*100);
//those vars were declared before
//here's the function that return the sigsegv error
int BuildCMD(enum CMD cmd,int *values,float Res,char *dataBuff)
//this line cause the error,it's just a formatted parameters list
//note:same error with just
I'm pretty sure that the problem is "dataBuff" since even if i use sprintf to try to store a normal constant string it gives me the same error.
It's just...i can't figure out what i'm doing wrong.
Thanks in advance.
as function header:
int BuildCMD(enum CMD cmd,int *values,float Res,char dataBuff)
as sprintf call:
sprintf(&dataBuff,"0*;%d;%d;%d;%d;%d;%d;%.5f|\n",cmd,values,values,values,values,values,Res); You've unnecessarily abbreviated the very line on which you think the problem exists. Don't do that--show us the real sprintf statement you're using in your actual code.