Strange string problem ...
-
hi, in my code i do the following thing
char* pByte = new char[16]; memset( pByte, 0, 16 ); memcpy( pByte,"çj]%Þ6f$.JÛ.$(ñå", 16);
So, the content of my pByte pointer should be "çj]%Þ6f$.JÛ.$(ñå" (and all following characters until editor reach a null-terminated string character). But if i check in memory what my pointer contains, i see the following value : + pByte 0x04b78f98 "çj]%Ãz6f$.JÃ>.$ýýýý««««««««îþîþ" char * :doh: I don't understand why my content is modified. I'm using VC++ 2003. On another project i do exactly the same thing and my pointer is not modified. the two project have exactly the same settings ... This problem make me crazy X|, all suggestions are welcome. Thanks.First check memory is allocated or not. Then check ASCII value stored in pByte memory location in memory debug window.
-
Actually your code works fine on my system, the 16 characters of
pByte
being initialized to"çj]%Þ6f$.JÛ.$(ñå"
of course the debugger shows some garbage at the end, since the string is not0
terminated. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
"the debugger shows some garbage at the end, since the string is not 0 terminated" as Pallini told, this what is happening in your case. you better increase your buffer length to 17 and check again, then the debugger shows the string properly.
-
Actually your code works fine on my system, the 16 characters of
pByte
being initialized to"çj]%Þ6f$.JÛ.$(ñå"
of course the debugger shows some garbage at the end, since the string is not0
terminated. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
This code works well on another project too. i'm looking for a preprocessor or an option who should modify my string but i have no idea.
That code must work. Are you sure there aren't aother statements between assignment and check?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Ahryman40k wrote:
But if i check in memory what my pointer contains, i see the following value : + pByte 0x04b78f98 "çj]%Ãz6f$.JÃ>.$ýýýý««««««««îþîþ" char *
How are you verifying this?
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
With the VC++ 2003 debugger. In step by step debug mode. Just after memcpy, i'm looking the content of my pointer. but datas allocated are different from original datas. I'm looking for an option or a preprocessor whitch could modify datas ... This problem appears in a project that i don't maintain. In this project when copying "ç" character in a char pointer, the result become "ç". I have all code sources. the whole project is well compilated. I don't know what it happens in this project ...
-
That code must work. Are you sure there aren't aother statements between assignment and check?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain ClarkeThis is my problem. It MUST work but it doesn't work ! :s no override on new operator. just this simple code: char* pByte = new char[16]; memset( pByte, 0, 16 ); memcpy( pByte,"çj]%Þ6f$.JÛ.$(ñå",17); who do not its job ! Is there any VC++ options who can change this ?? ( this is not a UNICODE problem and i really have no idea where the problem comes from )
-
The problem is not what the debugger diplay, but the content displayed. i know my data is not null-terminated, but each character should be the same as the original string.
Ahryman40k wrote:
i know my data is not null-terminated...
Then you know why it appears wrong. The terminating nul character has been overwritten.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
First check memory is allocated or not. Then check ASCII value stored in pByte memory location in memory debug window.
-
hi, in my code i do the following thing
char* pByte = new char[16]; memset( pByte, 0, 16 ); memcpy( pByte,"çj]%Þ6f$.JÛ.$(ñå", 16);
So, the content of my pByte pointer should be "çj]%Þ6f$.JÛ.$(ñå" (and all following characters until editor reach a null-terminated string character). But if i check in memory what my pointer contains, i see the following value : + pByte 0x04b78f98 "çj]%Ãz6f$.JÃ>.$ýýýý««««««««îþîþ" char * :doh: I don't understand why my content is modified. I'm using VC++ 2003. On another project i do exactly the same thing and my pointer is not modified. the two project have exactly the same settings ... This problem make me crazy X|, all suggestions are welcome. Thanks.Your source code file has been saved as UTF-8, but the compiler is reading it as Windows-1252 or whatever your local code page is. Don't use characters outside of ASCII in source code, use the \x escape instead (or \u if your compiler supports it).
--Mike-- Visual C++ MVP :cool: LINKS~! CP SearchBar v3.0 | C++ Forum FAQ I work for Keyser Söze
-
Your source code file has been saved as UTF-8, but the compiler is reading it as Windows-1252 or whatever your local code page is. Don't use characters outside of ASCII in source code, use the \x escape instead (or \u if your compiler supports it).
--Mike-- Visual C++ MVP :cool: LINKS~! CP SearchBar v3.0 | C++ Forum FAQ I work for Keyser Söze
Michael Dunn wrote:
Your source code file has been saved as UTF-8, but the compiler is reading it as Windows-1252 or whatever your local code page is. Don't use characters outside of ASCII in source code, use the \x escape instead (or \u if your compiler supports it).
You're right, my source file was save as UTF-8, that's why what i see was different than what my string appenned. Thank you. :laugh: