|
What is your date variable type?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
what about CTime and CTimeSpan ?
|
|
|
|
|
Thank you, i got the soln
I am using COleDateTime and COleDateTimeSpan.
COleDateTime d;
COleDateTimeSpan s(2,0,0,0);
d::GetCurrentTime();
d = d + s;
|
|
|
|
|
Can anybody suggest a light weight HTTP parser library(DLL) preferably open source?
|
|
|
|
|
Hi all,
I want to find the number of words in a string. That string only contain whitespace, tab space and the new line character. So I code it as follows.
int numberOfWords = 1;
string st(pBuffer);
for(int i = 0;i <= st.length(); i++)
{
if(pBuffer[i] == ' ')
{
numberOfWords ++;
}
if(pBuffer[i] == '\t')
{
numberOfWords ++;
}
if(pBuffer[i] == '\n')
{
numberOfWords ++;
}
}
cout << "\n" << numberOfWords;
But this code is odd. I mean say there is a whitespace and a tab space are occur with each other. Then the result is wrong. How can I avoid such odd points there.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: I mean say there is a whitespace and a tab space are occur with each other
Take a look if the character at i-1 and i+1 are valid before increasing the counter.
Eranga Thennakoon wrote: int numberOfWords = 1;
BTW... if you are asking about 2 spaces or 2 tabs together... then you should take care on empty buffer, so start in numberOfWords = 0 :P
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
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)
{
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
|
|
|
|
|
What about:
int count=0;
int len = strlen(pBuffer);
int i =0;
for ( ; ; )
{
while (pBuffer[i]==' ' || pBuffer[i] == '\t' || pBuffer[i] == '\n' && i < len)
{
i++;
}
if (i ==len ) break;
count++;
while (!( pBuffer[i]==' ' || pBuffer[i] == '\t' || pBuffer[i] == '\n') && i < len)
{
i++;
}
if (i == len) break;
}
It is odd, but has a chance to work
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Yes, it's work. But how can I avoid the multiple newline characters at the end.
Say my string is "One Two Three", and I've enter two times the enter key. So the the result is not 3, that is because of the additional new line characters. How can I avoid it. When I take the length it gives the length more than the original length.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Do you mean CR-LF pair? I f the answer is yes, then you have to handle the carriage return '\r' character too, for instance
...
while(pBuffer[i]==' ' || pBuffer[i] == '\t' ||
pBuffer[i] == '\n' || pBuffer[i] == '\r' && i < len)
...
and so on
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Oki, I got your point. But now I'm really confusing, if I've not take the definition in wrong way. That is, carriage return can be occur within a string? My initial code detect only the final newline characters, not within the string.
Can you explain it little more.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: That is, carriage return can be occur within a string?
In fact, any caratter can.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
That is interesting, and I found that another thing also. When I use your code line that multiple newline at the end avoided.
Ok, say I type a word then any number of spaces, tabs the answer is right. If I add a newline after all those things, the answer is added one more. Only one and it is happened within the string. That mean carriage return can't avoid within the string???? or...??
I appreciate your help all the time...
Eranga
|
|
|
|
|
AS I suggested you can augment my code to intercept and discard carriage returns ('\r' ) as well as any other character.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Yep, I think so. It is the easiest way to do it. I'll work it out and if I got any issue back to here..
I appreciate your help all the time...
Eranga
|
|
|
|
|
you could use a string tokenizer[^], and then just count the occurences (that mean, is the example above, count the vector size)...
|
|
|
|
|
Ok, I've read that page. But little bit difficult to me, because vectors and stuff in C++ are new topics for me. Anyway thanks for the link again, I'll try it after doing some works with vectors.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Another option would be to use strtok.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
How can I change the color of GridLines that appears when I use the EXTENDED STYLE for List Control.
m_ListCtrl.SetExtendedStyle(LVS_EX_CHECKBOXES | LVS_EX_GRIDLINES);
With Reagards
Vikas
|
|
|
|
|
I want to use ZwCreateFile() and ZwQueryInformationFile() in wdm.h or ntddk.h.
but if I incluce either of above,there would be hundreds of typedef redefining errors like PVOID64,and so on. The messages said the types had been defined in winnt.h.
But if I conclude winnt.h there would be more errors occur!
Someone would tell me how to resolve such errors?
Thanks.
GOOD LUCK
|
|
|
|
|
what about the preprocessor #ifdef, #ifndef or #pragma? Do they help?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Nelek wrote: what about the preprocessor #ifdef, #ifndef or #pragma? Do they help?
i don't think they will. in fact, i hope files from microsoft SDKs like wdm.h or ntddk.h already have such inclusion securities...
|
|
|
|
|
You cannot include the ntddk.h in an application with the windows.h. so the only turn around is to copy the function definition from the ntddk.h and paste in one for your local file.
|
|
|
|
|
Hi Naveen,
Naveen wrote: so the only turn around is to copy the function definition from the ntddk.h and paste in one for your local file.
that's bad. where will he find the implementation of the function then ?
|
|
|
|
|
toxcct wrote: that's bad.
But thats the only way. You might be aware that that function are implemeted in the ntdll.dll. But Platform SDK or visual c++ dosent offer a ntdll.lib file so that he can staticaly link his application to ntdll.dll. So only chance is to load that dll dynamically and call those function.
|
|
|
|