Click here to Skip to main content
15,890,186 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
GeneralRe: searching within strings Pin
jon-8028-Jul-06 8:08
professionaljon-8028-Jul-06 8:08 
Thanks.. I have updated the code accordingly, adding also a memcpy so that memcpy is used to copy the variables to local variables. I assume that this is a workaround for strstr (right?).

However, token seems to have a value of 0xcccccccc <Bad Ptr> when debugging, so the program never really checks.

Code:
int CSentenceAr::HowManyWords(const char strWord[MAX_WORD_LENGTH])
{
// initialize local variables
char strSearch[MAX_WORD_LENGTH] = {0};
memcpy(strSearch, strWord, MAX_WORD_LENGTH); //copies fixed array to strSearch
char* ptrToken = 0;

char strSentence[MAX_SENTENCE_LENGTH] = {0};
int iWordCount = 0;


for (int iCurrent = 0; iCurrent <= iNumberOfLines; iNumberOfLines++)
{

ptrToken = strstr(strSentence, strSearch);

while (ptrToken != 0 && *ptrToken != 0)
{ memcpy(strSentence, this->strSentence[iCurrent], MAX_SENTENCE_LENGTH);

if (strlen(ptrToken) > 0)
{ ++iWordCount;
ptrToken += strlen(strWord);
if (ptrToken >= strSentence + MAX_WORD_LENGTH)
{break;}
}
ptrToken = strstr(ptrToken, strSearch);
}
}
return (int) iWordCount;
}

Jon
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 
GeneralRe: Why doesn't this work? Simple file I/O Pin
Zac Howland26-Jul-06 8:56
Zac Howland26-Jul-06 8:56 

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.