| | |
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?
Views: 259 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






