sprintf_s corrupt results
Hello,
I have a problem with sprintf_s and I have not been able to solve.
Why below sprintf_s buffer results come out corrupt? The alternative cout (which directly prints the values) produces correct results.
1 2 3 4 5 6
|
char buf[255];
sprintf_s(buf,sizeof(buf),"Region Report(%s): size=%d peds=%d density=%.2f, ReportMapColor=%d, color=%d", name,size,pedCount,density,this->reportMapColor,this->colorVal);
cout << string(buf) << endl;
cout << "normal, name:" << name << ", size:" << size << ", pedcount:" << pedCount << ", density:" << density << ", reportMapColor:" << this->reportMapColor << " , colorval:" << this->colorVal << endl;
|
Region Report(á(@): size=1953525093 peds=-842203015 density=-6277438562204192500000000000000000000000000000000000000000000000000.00, ReportMapColor=5, color=15
normal, name:wall, size:0, pedcount:0, density:0, reportMapColor:10 , colorval:0 |
Thank you for your time.
What is the return value of sprintf_s?
Vlad, thanks for your time.
1 2 3 4 5 6
|
char buf[255];
int retval=0;
retval=sprintf_s(buf,255,"Region Report1(%s): size=%d peds=%d density=%.2f, ReportMapColor=%d, color=%d", name,size,pedCount,density,this->reportMapColor,this->colorVal);
cout << string(buf) << endl;
cout << "Region Report2(" << name << "): size=" << size << ", peds=" << pedCount << ", density=" << density << ", ReportMapColor=" << this->reportMapColor << " , color=" << this->colorVal << endl;
cout << "sprintf_s returns: " << retval << endl;
|
Region Report1(á⌠☼): size=1953525093 peds=-842203015 density=-6277438562204192500000000000000000000000000000000000000000000000000.00, ReportMapColor=5, color=15
Region Report2(empty): size=0, peds=0, density=0, ReportMapColor=0 , color=16777215
sprintf_s returns: 160 |
Topic archived. No new replies allowed.