|
Hockey wrote:
I thought it would decrement i ... until i == 0
No, the loop runs as long as the condition i>=0 is true. When i is 0, the test becomes 0>=0 which is true, so the loop runs. If you want to stop when i is 0, the test should be i>0
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
I understand true would cause the loop to iterate again, but I still can't get the code working...
I'm trying to extract a word given an offset into a buffer using space as delimiters, this is what I have so far and it doesn't work...and I have no idea why...
for(int i=nIndex; i>0; i++){
if(csBuff[i]==chDelim || csBuff[i]==LF) break;
}
for(int j=i; j<csBuff.GetLength(); j++){
if(csBuff[j]==chDelim || csBuff[i]==CR) break;
csWord += csBuff[j];
}
Any idea?
Thank again
How do I print my voice mail?
|
|
|
|
|
Hockey wrote:
for(int i=nIndex; i>0; i++){
Are you sure that i++ is intentional? That, coupled with the i>0 condition, means that this is potentially a "forever" loop. The only thing that would cause the loop to exit, besides i becoming negative after about 231, would be if either of the conditions in the if statement were true.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
May be he typeoed coz his original post has i--;
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|
|
Yes, that notion was considered.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
It is normal.
Remember that the syntax of for statement is defined as:
for(init_statement ; condition ; expression) exp_2;
The expression (in the case, i--) will continue to work (decrement) till the condition becomes false, then the execution leaves the for loop. In the case, i>=0 is still true while i is zero at that time, thus the expression (i--) will be executed once more to expect the condition to become false.
If you hope it exit the for loop at the time i = 0, you may write this way:
for(int i = nIndex; ; i--)
{
if(csBuff[i] == chDelim || csBuff[i] == LF)
break;
if(0 == i)
break;
}
Maxwell Chen
|
|
|
|
|
How do i show a balloon window with my trayicon to show some events accoring.
The balloon window similar to what you get when a new hardware is detected by windows.
Regards.
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|
|
hi, guys
i need to use a CTypedPtrList templet structure in my program.
here is my code: (CFreqStandard is a class which i derived from CObject and it's basically used to store some data)
class CSDIgDoc : public CDocument
{
protected: // create from serialization only
CSDIgDoc();
DECLARE_DYNCREATE(CSDIgDoc)
protected:
//CTypedPtrList<coblist,cfreqstandard*> FreqList;
//CString StandardName;
CString StandardName;
CTypedPtrList<coblist,cfreqstandard> m_FreqList;/////////////////////
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSDIgDoc)
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CSDIgDoc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CSDIgDoc)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
but when i compile i always get an error in the line
CTypedPtrList<coblist,cfreqstandard> m_FreqList;
it shows that "'CTypedPtrList' : missing storage-class or type specifiers"
what is the problem in this case?
Thank you very much in advance
|
|
|
|
|
You never defined the types to use for the template, like this for example:
typedef CTypedPtrList<CObList, CMyObject*> m_FreqList;
Have a look to this article[^] of MSDN for a sample.
HTH,
K.
Mais donnez-moi aussi
Le courage et la force et la foi
Car vous êtes le seul à donner
Ce que l'on ne peut obtenir que de soi.
|
|
|
|
|
Hi Friends,
How can i programmatically cancel a message box that popped during a startup of a application
thanx,
John
|
|
|
|
|
Seems like writing a loader, or removing a nag screen
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
I declear a CTime valiable and set it's value before 1970-1-1, it will cause a assertion failed error(timecore.cpp), I realized that 1970-1-1 is the defaule value for CTime, anybody encounter this problem before? please help me out, thanks a lot.
|
|
|
|
|
CTime objects can contain times from 1970-1-1 to somewhere in 2038. (you should check the validity of the input yourself)
if you want to have dates outside that period you can use the COleDateTime class.
Regards,
Davy
|
|
|
|
|
I have been using FindFirstUrlCacheEntry/FindNextUrlCacheEntryA/DeleteUrlCacheEntry without specifying wininet.lib in the object/library modules in my project options.
But when I added the cache group functions (FindFirstUrlCacheGroup, etc), I could not build my project without adding wininet.lib to the object/library modules.
any ideas why this is so?
|
|
|
|
|
just add it and please don't waste our time.
Don't try it, just do it!
|
|
|
|
|
I want to statically link the DLL MSVCP60.DLL to my EXE. How do I specify this in my project options? I am using visual studio 6.
1. Is it by specifying 'Use MFC in static library'? I dont use MFC. Even after specifying this option my exe size is same.
2. Under link, Input category, specify the lib under Object/library modules. What is the lib for MSVCp60.DLL? If I say, msvcp60.lib, it is not found.
I am using dependancy walker to see the DLLs my EXE is dependant on. If I link a DLL statically, I assume it wont show in the dependancy walker any more, right?
Thanks
Fl.
|
|
|
|
|
Flace wrote:
statically link the DLL
I think you've missed the point a little. DLL's are Dynamically Linked Libraries, they require dynamic linking. The .lib (static libraries) that you link to for implicit linking (at compile time) only forward responsibility to the DLL. Even if it is possible to statically link to a DLL (I personally don't know how too, but I'm sure there are hacks to do it) why would you bother??? Just distribute the DLL with your executable if you aren't sure whether the client has it.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
Ok, got it. Thanks.
but just curious as to how to statically link a library. for ex, wininet.lib. What should I do to statically link this?
Thanks,
Fl.
|
|
|
|
|
It depends a on which compiler and IDE you are using. One of the easiest ways in VC.NET is to add wininet.lib to the edit box:
Project Properties -> Linker -> Input -> Additional Dependencies.
Most IDE's should have something similar.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
How do I take an input(integer value) from a textbox than assign that input into an array. The array is a 50 element array.
int sum,val;
//int* average = new int[50];
//int average[50];// Create an array dynamically pg.234
String* i = VoltsTextBox->Text;
int averagr[val] = Int32::Parse(i);
|
|
|
|
|
What type of application are you working on? SDK or MFC?
Maxwell Chen
|
|
|
|
|
windows forms micosoft visual studio.net.
|
|
|
|
|
Right-click at the edit box control to add a data member of type int (for example, m_iMyVal). Then have a look at the function UpdateData(FALSE) to sync the value of m_iMyVal with the value (text) seen in that edit box. Finally you add the value into your array, and loop the step to complete the array.
Maxwell Chen
|
|
|
|
|
Hi
I have a problem with the thread and class.
I created a thread from a function and in the thread function, i called and init a class but not using the new and delete method. There is a problem when the thread ended as the class destructor was not activated when i called ExitThread...an example below
main function()
{
CreateThread(.....,ThreadProc,...);
}
ThreadProc()
{
CDB_Database Data(); //Class Init
DWORD dwRecords;
HANDLE hFile; etc
OpenFile();
...
....
...
ExitThread(0);
}
my problem is everytime i called creatThread, the class constructor will be activated but when i called ExitThread, the class destructor was not activated.
So is the resources used by the thread free when i called exitThread as i seems to have sharing violation inside the function
Thank you for ur advise
|
|
|
|
|
The ExitThread() function never returns, so the ThreadProc() doesn't reach its end and destructors don't get called. One way to solve this is to add another pair of braces:
ThreadProc()
{
{
CDB_Database Data();
DWORD dwRecords;
HANDLE hFile; etc
OpenFile();
}
ExitThread(0);
}
Now Data is destroyed when code exits the inner braces, just before ExitThread()
|
|
|
|