|
Thank you so much.
|
|
|
|
|
Aljechin wrote: I need to copy a string which may contain NULL characters in between
How about std::copy[^]?
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
char szSource[23] = {"Before\0After"};<br />
char szDest[23];<br />
<br />
ptr = memcpy(szDest,szSource,22);<br />
printf("%s %d",szDest,strlen(szDest));
I went through that page, but not getting it. Can you show me a small code snippet of how do i copy that szSource into szDest? Sorry if a very elementary question.
|
|
|
|
|
What are you trying to do exactly ?
Is not because memcpy sucessfully copied the source into the destination that the '\0' character will be removed. It will still be present in the new string so as soon as you try to get its length or print the string, you will only have the begining of the string. This is totally logical.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
What I am doing? PIP (Peripheral Interface Programming). I have generated a sequence of binary data which will be understood by a peripheral device. For example, we issue a print command from notepad. Its not the .txt file that is sent to the printer by the OS. But a series of printer-understood data is sent. My program generates such device-understandable data which could be just dumped into the port of the device and it will print some meaningful text or act accordingly. I have this binary (kinda junk) stored in unsigned char array. So, I am trying to figure out a way to do this.
|
|
|
|
|
So, what is the problem ? Your data is there but if you try to display it with a function that waits for a string, you won't be able to see past the zero char. Just send your buffer and it will work. You need to remember the size of your string of course because strlen won't work.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
|
Aljechin wrote: char szSource[23] = {"Before\0After"};
char szDest[23];
ptr = memcpy(szDest,szSource,22);
printf("%s %d",szDest,strlen(szDest));
<br />
char szSource[23] = {"Before\0After"};<br />
char szDest[23];<br />
<br />
std::copy(szSource, szSource + 23, szDest);<br />
However, as Cedric already noted, don't expect that printf and strlen show the whole thing if you have embedded zeroes.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Thank you so much. I will try this.
|
|
|
|
|
Hi all
How can I get file size in mega bytes ?
Is there any good API, for this ?
I have a MFC prpject.
thank you.
|
|
|
|
|
big_denny_200 wrote: Hi all
How can I get file size in mega bytes ?
Is there any good API, for this ?
GetFileSizeEx() for reteriving size of File and convert that into MB by divinding it by 1024 *1024
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hi ThatsAlok,
How are you?
and StrFormatByteSizeA
whitesky
|
|
|
|
|
WhiteSky wrote: How are you?
Fine
WhiteSky wrote: nd StrFormatByteSizeA
Will try!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
WhiteSky wrote: StrFormatByteSizeA
Thanks for Api!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
yo're welcome Mr Alok Gupta
whitesky
|
|
|
|
|
WhiteSky wrote: welcome Mr Alok Gupta
Even Alok will do
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
open the file using CFile
then call "GetLength"
it will give u size in bytes divide it by (1024*1024) ( im not sure this calculation is correct)
SaRath.
"Don't Do Different things... Do Things Differently..."
|
|
|
|
|
SaRath C wrote: open the file using CFile
Not a good idea as Open() is an expensive call, not to mention that it could easily fail if another process has the file open.
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
|
my code:
BEGIN_EVENTSINK_MAP(CBrowserPage, CDialog)
//{{AFX_EVENTSINK_MAP(CBrowserPage)
ON_EVENT(CBrowserPage, IDC_EXPLORER1, 271 , NavigateError, VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)
ON_EVENT(CBrowserPage, IDC_EXPLORER1, 252 /* NavigateComplete2 */, OnNavigateComplete2Explorer1, VTS_DISPATCH VTS_PVARIANT)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
OnNavigateComplete2Explorer1 can work,
NavigateError can't work,why?
my ie is 6.0
thanks!
|
|
|
|
|
had got it ,
ON_EVENT(CBrowserPage, IDC_EXPLORER1, 271 , NavigateErrorExplorer1,VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)
can work
thanks
|
|
|
|
|
Hi again buddies
Can anyone help me with a couple of questions on CString
i'm trying to use it for the first time
CString str("Ma%"); //CString' : undeclared identifier(i include string)
also how can i convert a string to CString and vice versa
Thanks a lot
|
|
|
|
|
CString is a MFC (or ATL) class. if you don't have a MFC project, you won't see it.
did you create a console project ?
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
U need MFC support for the application.
CString is defined at "Afx.h"
if add support to for MFC, u can simply use the basic mfc classes.
These are the main include files.
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
in a normal MFC application, this will be included at "StdAfx.h"
SaRath
"D on't blindly follow rules you read somewhere without verifying that it makes sense for your situation!"
|
|
|
|
|
Converting string to CString
<br />
string stdStr = "Test";<br />
CString strText = stdStr.c_str();<br />
SaRath
"D on't blindly follow rules you read somewhere without verifying that it makes sense for your situation!"
|
|
|
|