Click here to Skip to main content
16,008,719 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionMigrating from VC 6.0 to 7.1 Pin
Identity Undisclosed20-Nov-05 23:57
Identity Undisclosed20-Nov-05 23:57 
QuestionSocket on Thread PB Pin
rofrantz20-Nov-05 23:14
rofrantz20-Nov-05 23:14 
Questionmemstr Pin
kevincwong20-Nov-05 22:50
kevincwong20-Nov-05 22:50 
AnswerRe: memstr Pin
Rage21-Nov-05 0:58
professionalRage21-Nov-05 0:58 
AnswerRe: memstr Pin
kakan21-Nov-05 2:34
professionalkakan21-Nov-05 2:34 
AnswerRe: memstr Pin
vikas amin21-Nov-05 2:48
vikas amin21-Nov-05 2:48 
AnswerRe: memstr Pin
James R. Twine21-Nov-05 6:02
James R. Twine21-Nov-05 6:02 
AnswerRe: memstr Pin
PJ Arends21-Nov-05 11:32
professionalPJ Arends21-Nov-05 11:32 
As was mentioned before, strstr is the closest thing, but it is limited in that NULL characters terminate the buffers. So I have used this code:
#include <string.h>
 
char * _memmem(const char *mem, size_t mem_size, const char *sub, size_t sub_size)
{
    // returns a pointer of the first occurance of a sub-buffer in a memory buffer
    // returns NULL if the sub-buffer was not found
    // is not limited by embedded NULLs in either the memory buffer or the sub-buffer
    //
    // Parameters:
    //    mem      - The memory buffer to scan
    //    mem_size - The size, in bytes, of the memory buffer
    //    sub      - The sub buffer to find
    //    sub_size - The size, in bytes, of the sub buffer
 
    char *ret = NULL;
    char *ptr = const_cast<char *>(mem);
    while (ptr && !ret)
    {
        ptr = reinterpret_cast<char *>(memchr(ptr, *sub, mem_size - (sub_size - 1) - (int)(ptr - mem)));
        if (ptr)
        {
            if (!memcmp(ptr, sub, sub_size))
                ret = ptr;
            ++ptr;
        }
    }
 
    return ret;
}
[edit]
cleaned up the code a little
[/edit]



"You're obviously a superstar." - Christian Graus about me - 12 Feb '03

"Obviously ???  You're definitely a superstar!!!" - mYkel - 21 Jun '04

"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05

Within you lies the power for good - Use it!

-- modified at 18:12 Monday 21st November, 2005
Questiondefault button Pin
Nishad S20-Nov-05 22:34
Nishad S20-Nov-05 22:34 
AnswerRe: default button Pin
Owner drawn20-Nov-05 22:40
Owner drawn20-Nov-05 22:40 
AnswerRe: default button Pin
toxcct21-Nov-05 2:23
toxcct21-Nov-05 2:23 
AnswerRe: default button Pin
Mike Dimmick21-Nov-05 7:27
Mike Dimmick21-Nov-05 7:27 
QuestionHow to move cursor to bottom of view in SDI ? Pin
quangpk20-Nov-05 22:07
quangpk20-Nov-05 22:07 
AnswerRe: How to move cursor to bottom of view in SDI ? Pin
Russell'21-Nov-05 0:55
Russell'21-Nov-05 0:55 
GeneralRe: How to move cursor to bottom of view in SDI ? Pin
quangpk21-Nov-05 15:05
quangpk21-Nov-05 15:05 
AnswerRe: How to move cursor to bottom of view in SDI ? Pin
David Crow21-Nov-05 3:27
David Crow21-Nov-05 3:27 
GeneralRe: How to move cursor to bottom of view in SDI ? Pin
quangpk21-Nov-05 15:02
quangpk21-Nov-05 15:02 
GeneralRe: How to move cursor to bottom of view in SDI ? Pin
David Crow22-Nov-05 3:00
David Crow22-Nov-05 3:00 
QuestionLoggin in a modeledd dialog Pin
kk_vp20-Nov-05 21:20
kk_vp20-Nov-05 21:20 
AnswerRe: Loggin in a modeledd dialog Pin
kakan20-Nov-05 22:01
professionalkakan20-Nov-05 22:01 
GeneralRe: Loggin in a modeledd dialog Pin
kk_vp20-Nov-05 22:22
kk_vp20-Nov-05 22:22 
GeneralRe: Loggin in a modeledd dialog Pin
vikas amin20-Nov-05 22:40
vikas amin20-Nov-05 22:40 
GeneralRe: Loggin in a modeledd dialog Pin
kakan20-Nov-05 22:42
professionalkakan20-Nov-05 22:42 
GeneralRe: Loggin in a modeledd dialog Pin
kk_vp21-Nov-05 1:55
kk_vp21-Nov-05 1:55 
GeneralRe: Loggin in a modeledd dialog Pin
kakan21-Nov-05 2:18
professionalkakan21-Nov-05 2:18 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.