M
merrittr
I am trying to build variables for a function using sprintf. However
they don't seem to be proper
char strings since submiting literals seems to work fine. Any advice
to get me rolling?
sprintf( i1, "%s %s \0",v1,v2 );
sprintf( i1, "%s %s \0",v3,v4 );
printf("answer %s\n",add(cTypeCurr,i1,i2));
printf("answer %s\n",add("i","3 i","4 i"));
here is the output I get:
---retval èG♥ èG♥
---0.000000 3 i 4 i
the function:
char *add(char *ctype, char *i, char *j)
{
double x,y,z,a;
static char retval[10]="retval";
printf("---%s %s %s\n",retval,i,j); <--output line
x=atof(i);
y=atof(j);
z=x+y;
sprintf( retval, "%f",z );
return retval;
}
they don't seem to be proper
char strings since submiting literals seems to work fine. Any advice
to get me rolling?
sprintf( i1, "%s %s \0",v1,v2 );
sprintf( i1, "%s %s \0",v3,v4 );
printf("answer %s\n",add(cTypeCurr,i1,i2));
printf("answer %s\n",add("i","3 i","4 i"));
here is the output I get:
---retval èG♥ èG♥
---0.000000 3 i 4 i
the function:
char *add(char *ctype, char *i, char *j)
{
double x,y,z,a;
static char retval[10]="retval";
printf("---%s %s %s\n",retval,i,j); <--output line
x=atof(i);
y=atof(j);
z=x+y;
sprintf( retval, "%f",z );
return retval;
}