Click here to Skip to main content
15,888,351 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generaladd int to date Pin
Try17-Dec-07 0:41
Try17-Dec-07 0:41 
QuestionRe: add int to date Pin
CPallini17-Dec-07 0:48
mveCPallini17-Dec-07 0:48 
GeneralRe: add int to date Pin
Maximilien17-Dec-07 0:59
Maximilien17-Dec-07 0:59 
GeneralRe: add int to date Pin
Try17-Dec-07 1:09
Try17-Dec-07 1:09 
GeneralHttp Parser Library Pin
ktm TechMan17-Dec-07 0:15
ktm TechMan17-Dec-07 0:15 
GeneralCount words in a string Pin
CodingLover16-Dec-07 23:33
CodingLover16-Dec-07 23:33 
GeneralRe: Count words in a string Pin
Nelek16-Dec-07 23:58
protectorNelek16-Dec-07 23:58 
GeneralRe: Count words in a string Pin
CodingLover17-Dec-07 0:12
CodingLover17-Dec-07 0:12 
Nelek wrote:
Take a look if the character at i-1 and i+1 are valid before increasing the counter.


Or should I check i and i+1. I'll use it and failed.


Nelek wrote:
if you are asking about 2 spaces or 2 tabs together


I've change my code as this.

bool isLastCharBlank = true;
int iWordCount = 0;

char * szTemp = szInputString;

while(*szTemp)
{
    // Whitespase, tab and newline
    if ((*szTemp == ' ') || (*szTemp == '\n'))
    {
        isLastCharBlank = true;
    }

    else if (isLastCharBlank)
    {
        iWordCount++;
        isLastCharBlank = false;
    }
    szTemp++;
}
cout << iWordCount;


Since I've use a pointer to the string I can avoid such instances (I mean 2 spaces, 2 tabs, a tab and a space etc)

But now my question is how to avoid multiple new line characters at the end.
I appreciate your help all the time...
Eranga Smile | :)

AnswerRe: Count words in a string Pin
CPallini16-Dec-07 23:58
mveCPallini16-Dec-07 23:58 
GeneralRe: Count words in a string Pin
CodingLover17-Dec-07 0:35
CodingLover17-Dec-07 0:35 
GeneralRe: Count words in a string Pin
CPallini17-Dec-07 0:43
mveCPallini17-Dec-07 0:43 
GeneralRe: Count words in a string Pin
CodingLover17-Dec-07 0:59
CodingLover17-Dec-07 0:59 
GeneralRe: Count words in a string Pin
CPallini17-Dec-07 1:01
mveCPallini17-Dec-07 1:01 
GeneralRe: Count words in a string Pin
CodingLover17-Dec-07 1:07
CodingLover17-Dec-07 1:07 
GeneralRe: Count words in a string Pin
CPallini17-Dec-07 2:11
mveCPallini17-Dec-07 2:11 
GeneralRe: Count words in a string Pin
CodingLover17-Dec-07 16:28
CodingLover17-Dec-07 16:28 
GeneralRe: Count words in a string Pin
toxcct17-Dec-07 1:28
toxcct17-Dec-07 1:28 
GeneralRe: Count words in a string Pin
CodingLover17-Dec-07 16:33
CodingLover17-Dec-07 16:33 
GeneralRe: Count words in a string Pin
krmed17-Dec-07 1:58
krmed17-Dec-07 1:58 
GeneralChanging the color of GridLInes Pin
Vikas_12316-Dec-07 22:55
Vikas_12316-Dec-07 22:55 
Questionhot to resolve such redefined type errors? Pin
kcynic16-Dec-07 22:25
kcynic16-Dec-07 22:25 
AnswerRe: hot to resolve such redefined type errors? Pin
Nelek16-Dec-07 22:45
protectorNelek16-Dec-07 22:45 
GeneralRe: hot to resolve such redefined type errors? Pin
toxcct16-Dec-07 23:00
toxcct16-Dec-07 23:00 
AnswerRe: hot to resolve such redefined type errors? Pin
Naveen16-Dec-07 23:14
Naveen16-Dec-07 23:14 
GeneralRe: hot to resolve such redefined type errors? Pin
toxcct17-Dec-07 0:15
toxcct17-Dec-07 0:15 

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.