Click here to Skip to main content
15,914,419 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: searching within strings Pin
David Crow26-Jul-06 8:22
David Crow26-Jul-06 8:22 
GeneralRe: searching within strings Pin
jon-8026-Jul-06 9:12
professionaljon-8026-Jul-06 9:12 
GeneralRe: searching within strings Pin
David Crow26-Jul-06 9:18
David Crow26-Jul-06 9:18 
QuestionRe: searching within strings Pin
jon-8026-Jul-06 10:05
professionaljon-8026-Jul-06 10:05 
AnswerRe: searching within strings Pin
David Crow26-Jul-06 10:12
David Crow26-Jul-06 10:12 
AnswerRe: searching within strings [modified] Pin
Zac Howland26-Jul-06 10:17
Zac Howland26-Jul-06 10:17 
GeneralRe: searching within strings Pin
jon-8027-Jul-06 7:46
professionaljon-8027-Jul-06 7:46 
GeneralRe: searching within strings Pin
Zac Howland28-Jul-06 3:38
Zac Howland28-Jul-06 3:38 
My apologies, the algorithm I posted will count the number of words in a character array. To find the number of times a substring appears in the array, you need to modify the algorithm to use strstr instead of strtok:

unsigned long HowManyWords(const char strWord[MAX_WORD_LENGTH], const char* substring)
{
        char buffer[MAX_WORD_LENGTH] = {0};
        memcpy(buffer, strWord, MAX_WORD_LENGTH);
        char* token = 0;
        unsigned long wordCount = 0;
        token = strstr(buffer, substring);
        while (token != 0 && *token != 0)
        {
                if (strlen(token) > 0)
                {
                        ++wordCount;
                        token += strlen(substring);
                        if (token >= buffer + MAX_WORD_LENGTH)
                        {
                                break;
                        }
                }
                token = strstr(token, substring);
        }
        return (int)wordCount;
}


If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week

Zac

GeneralRe: searching within strings Pin
jon-8028-Jul-06 8:08
professionaljon-8028-Jul-06 8:08 
GeneralRe: searching within strings Pin
Zac Howland28-Jul-06 9:05
Zac Howland28-Jul-06 9:05 
GeneralRe: searching within strings Pin
jon-8028-Jul-06 22:18
professionaljon-8028-Jul-06 22:18 
AnswerRe: searching within strings Pin
jon-8028-Jul-06 22:53
professionaljon-8028-Jul-06 22:53 
GeneralRe: searching within strings Pin
jon-802-Aug-06 10:07
professionaljon-802-Aug-06 10:07 
AnswerRe: searching within strings Pin
Zac Howland26-Jul-06 9:13
Zac Howland26-Jul-06 9:13 
QuestionHow to write to DataBase MS Access Pin
nahitan26-Jul-06 7:28
nahitan26-Jul-06 7:28 
AnswerRe: How to write to DataBase MS Access Pin
Hamid_RT26-Jul-06 7:36
Hamid_RT26-Jul-06 7:36 
GeneralRe: How to write to DataBase MS Access Pin
nahitan26-Jul-06 8:24
nahitan26-Jul-06 8:24 
QuestionRe: How to write to DataBase MS Access Pin
David Crow26-Jul-06 8:16
David Crow26-Jul-06 8:16 
AnswerRe: How to write to DataBase MS Access Pin
led mike26-Jul-06 8:41
led mike26-Jul-06 8:41 
QuestionWhy doesn't this work? Simple file I/O Pin
liuphil126-Jul-06 7:25
liuphil126-Jul-06 7:25 
AnswerRe: Why doesn't this work? Simple file I/O Pin
Zac Howland26-Jul-06 7:47
Zac Howland26-Jul-06 7:47 
GeneralRe: Why doesn't this work? Simple file I/O Pin
liuphil126-Jul-06 8:01
liuphil126-Jul-06 8:01 
GeneralRe: Why doesn't this work? Simple file I/O Pin
David Crow26-Jul-06 8:18
David Crow26-Jul-06 8:18 
GeneralRe: Why doesn't this work? Simple file I/O Pin
liuphil126-Jul-06 8:52
liuphil126-Jul-06 8:52 
GeneralRe: Why doesn't this work? Simple file I/O Pin
Zac Howland26-Jul-06 8:57
Zac Howland26-Jul-06 8:57 

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.