-
C++ Buffer Manipulation... memchr
void *memchr( const void *buf, int c, size_t count );
The function memchr is supposed to return a pointer to c (if it is found).
At least this is what MSFT says. However, notice that the return type is
"void" in the example above. It doesn't seem to return the pointer like
it is suppossed to.
I am trying to find a character in a buffer so that I can copy it out to
a string or character array (in other words... I want to pull sets of data
from a buffer using a delimiter). Memchr should help me do this, but I can't
get it to work.
Any ideas??
-
Re: C++ Buffer Manipulation... memchr
if you look carefully, the return type is 'void *' which is very
different from plain void. All you have to do is cast the resulting
pointer to char * or const char *.
There are much better ways to search a substring using real C++ strings.
However, if your code relies on char * buffers, then you'd probably
prefer to use <mem.h> and <string.h> functions instead. Look at the
strstr() function and strchr() in particular.
Danny
Brian wrote:
>
> void *memchr( const void *buf, int c, size_t count );
>
> The function memchr is supposed to return a pointer to c (if it is found).
> At least this is what MSFT says. However, notice that the return type is
> "void" in the example above. It doesn't seem to return the pointer like
> it is suppossed to.
>
> I am trying to find a character in a buffer so that I can copy it out to
> a string or character array (in other words... I want to pull sets of data
> from a buffer using a delimiter). Memchr should help me do this, but I can't
> get it to work.
>
> Any ideas??
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|