Click here to Skip to main content
       

C / C++ / MFC

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
AnswerRe: Empty StringmvpRichard MacCutchan30 Dec '12 - 22:22 
john5632 wrote:
first few bytes (10-15) are 0x0

john5632 wrote:
Buffer is having correct 512 bytes.

Both of these statements cannot be true. Either the buffer contains 512 characters or it contains something else, which may include some characters. Try showing how you read the buffer and what it contains when the read completes.
One of these days I'm going to think of a really clever signature.

AnswerRe: Empty StringmemberChris Meech31 Dec '12 - 1:57 
john5632 wrote:
But first few bytes (10-15) are 0x0

 
I think that is the key to your problem. The string of characters that will be placed into the szMailContent instance will consist of all characters in your buffer up until the first 0x0 is encountered. If you need your instance to be able to contain 0x0 characters, you will need to use some other class for that. Smile | :)
Chris Meech
I am Canadian. [heard in a local bar]
 
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
 
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

AnswerRe: Empty StringmemberDavidCrow31 Dec '12 - 5:25 
Something like:
BYTE buffer[512];
CFile file;
file.Read(buffer, sizeof(buffer));

"One man's wage rise is another man's price increase." - Harold Wilson

"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous


AnswerRe: Empty Stringmembermanem21k2 Jan '13 - 1:26 
You can make sure like this:
 
CFile file;
Char tempBuf[512];
file.Read(tempBuffer, 512);
GeneralRe: Empty Stringmemberjeron12 Jan '13 - 4:21 
manem21k wrote:
You can make sure like this:
 
CFile
file;
Char tempBuf[512];
file.Read(tempBuffer, 512);

 
Actually this will not work.
 
Char tempBuf[512]; <== wont compile there'e no Char data type
char tempBuf[512]; <== will compile
 
file.Read(tempBuffer, 512); <== wont compile, tempBuffer isn't declared
file.Read(tempBuf, 512); <== will compile
 
In other words see David's reply.
GeneralRe: Empty Stringmembermanem21k2 Jan '13 - 22:32 
Thanks for correcting the typos. Yeah I have't run this program but just sure the code will resolve the problem.
QuestionRe: Empty StringmvpCPallini2 Jan '13 - 10:09 
Why do you want to initialize a CString with binary data?
Veni, vidi, vici.

QuestionMFC Grid control 2.27memberBorisAnimal30 Dec '12 - 4:46 
Hi
I want to use this control.
I have VS2008. I create CMyDialog and create CGridCtrl m_Grid as a member. Then I fill grid without problem. I need to take focus cell text when I list grid by arrow down arrow up keys. What I have to do in message map of my class CMyDialog to react on these actions. Can You help me? Where I shoud look in documentation?
AnswerRe: MFC Grid control 2.27mvpRichard MacCutchan30 Dec '12 - 5:34 
I already answered this question here[^]. Please post in one forum only.
One of these days I'm going to think of a really clever signature.

QuestionWhen should printf round a floating number up for display?memberMember 419459328 Dec '12 - 5:11 
Specifically this statement:
	   printf("Chi square distribution for %s samples is %1.2f (%1.4f), and randomly\n",
	      String_Value, chisq, chisq);
 
I re-implemented this program in MASM to speed it up and I get the following difference (note that I added the (%1.4f)) to display the pre-rounded number to see why I was getting differences:
 
------------------------------------------------------------------ 17
Chi square distribution for 2048 samples is 6.13 (6.1250), and randomly
-------------------------------------------------------------- 17
Chi square distribution for 2048 samples is 6.12 (6.1250), and randomly
 
The question is, which one is correct according to the C spec? Should 6.1250 round up to 6.13 or should it take 6.1250+ to round up?
 
There are other questions such as the following:
           printf("of this %s %s file by %d (%2.2f) percent.\n\n", String_Value, samp,
  	          (short) (((100 * ((binary ? 1 : 8) - ent) / (binary ? 1.0 : 8.0)) + 0.5)),
  	                   ((100 * ((binary ? 1 : 8) - ent) / (binary ? 1.0 : 8.0))));
 
The cast to a (short) seems to truncate a 5.7 to 5, I had to add the (.... + 0.5) just before the cast in order to get the rounded number. Again, I added the (%2.2f) to display the rounding differences.
 
Which is correct according to the C spec, rounding or truncation?
 
The program being re implemented is John Walker's ENT.
 
Dave.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 24 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid