Re: sscanf problem.
- From: Norbert Unterberg <nunterberg@xxxxxxxxxxxxxxxxx>
- Date: Sun, 28 Oct 2007 09:23:41 +0100
Control Freq schrieb:
char cs[3];
BYTE b;
m_EntryMac[0].GetWindowText(cs, 2);
sscanf(cs, "%X", &b);
This code causes a fault at the sscanf line, but only in release mode.
Works fine in debug mode.
Ov course the code fails. Read the documentation of sscanf, in particular the section about the "scanf Type Field Characters":
character: X
Type of input expcted: Hexadecimal integer
Type of argument: Pointer to *int*
You are giving sscanf a pointer to a BYTE, not a pointer to an int. But sscanf will write an int into the variable. Maybe it does not fail in debug mode because the memory on the stack aroud the B varriable is not used. You were just lucky.
Do something like this:
> BYTE b;
int i;
> sscanf(cs, "%X", &i);
b = (BYTE)i;
Norbert
.
- References:
- sscanf problem.
- From: Control Freq
- sscanf problem.
- Prev by Date: sscanf problem.
- Next by Date: Re: New PowerPoint Indexer
- Previous by thread: sscanf problem.
- Next by thread: Re: sscanf problem.
- Index(es):
Relevant Pages
|