| | |
sprintf Issue
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Sep 2008
Posts: 62
Reputation:
Solved Threads: 0
I have a code snippet that strangely works one way on a fedora 6 machine and another way on a fedora 8 machine.
for eg. if isciistream.size=3
isciistream[0]=204
isciistream[1]=32
isciistream[2]=32
on a fedora 6 machine the output i get is
foo: -52,32,32
which is correct.
in a fedora 8 machine i get
foo:32,0,43
I'm not sure why...
any help is appreciated
C++ Syntax (Toggle Plain Text)
void Form1::SendToApp() { vector<int> isciistream; vector<int> fontstream; cout<<"Entering Form1::SendToApp()"<<endl; isciistream=wwnd->OnOK(); isciistream.push_back(32); char str[255]=""; cout<<"Size of IsciiStream:"<<isciistream.size()<<endl; for (int i=0;i<(int)isciistream.size();i++) { sprintf(str,"%s%c",str,isciistream[i]); cout << "isciistream[i] :" << isciistream[i]<< " str:"<<str[i]<<endl; } QString temp=str; const char *foo = temp.ascii(); cout<<"foo:"<<(int)foo[0]<<","<<(int)foo[1]<<","<<(int)foo[2]<<endl; }
for eg. if isciistream.size=3
isciistream[0]=204
isciistream[1]=32
isciistream[2]=32
on a fedora 6 machine the output i get is
foo: -52,32,32
which is correct.
in a fedora 8 machine i get
foo:32,0,43
I'm not sure why...
any help is appreciated
> sprintf(str,"%s%c",str,isciistream[i]);
1. Almost all C library functions have undefined behaviour when the source and destination overlap. You're reading from the string you're printing into.
2. QString temp=str;
> const char *foo = temp.ascii();
If you print out the bytes of str before this, are they OK?
Perhaps QString defaults to a wide char on F8
1. Almost all C library functions have undefined behaviour when the source and destination overlap. You're reading from the string you're printing into.
2. QString temp=str;
> const char *foo = temp.ascii();
If you print out the bytes of str before this, are they OK?
Perhaps QString defaults to a wide char on F8
![]() |
Similar Threads
- Issue with DirectX (Game Development)
- encapsulation issue (C++)
- character hexadeximal (C++)
- MessageBox issue (C)
- fgets crash issues (C)
Other Threads in the C++ Forum
- Previous Thread: New to C++
- Next Thread: template specialization for template member function?
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






