|
|
Don't mind me, I'm in a teaching mood!
There are three diffrent looping structures within The C Programming Language and C++ (an extension of C). There are:
- for
- while
- do-while
Here is a brief description for each:
- for: The for loop is mainly used to step through something, like an array. It syntax is "for( staring index ; condition ; increment ) Statement" These statements can be incremented (or decremented) by a known value, like 1, 3, 5, 56, ... You don't need all the items within the paranthesis, but you do need the semi-colons. Example:
for( x = 0; x < 10; x++ ) a[x] = x; for( ;; )... Here I have an endless loop. for( ; x < 10; ) ... Here it is like the while loop.
- while The while loop is used to do looping until a condition is met. One example for the while would be in polling something. You continue waiting until the event occurs then drop out of the loop. You can interchange the for/while exactly like one of the post stated. The condition testing is done at the beginning of the loop.
- do-while This loop structure is a different animal than the rest. Unlike the for/while loops where they must first pass the condition to execute, the do-while will always execute the loop once. The condition testing is done at the end of the loop instead of the beginning.
I hope this helps. The uses that I described are not hard and fast, but they can be used as a guide line if your new until you get more experience.
Larry J. Siddens
Cornerstone Communications
TAME THE DOCUMENT MONSTER
www.unifier.biz
|
|
|
|
|
Hi there
Example, new to this myself!!
{
//Create vector put 26 numbers into it
//using for loop
for(int i = 0; i < 26; ++i)
{
Vec.push_back(i * 2); // pushback * 2
//2,4,6,8,10......
cout << Vec.at(i) << "\n"; //Display
}
Not that dificult hey.
Regards bhangie
|
|
|
|
|
How can I know if user clicked on the balloon help for the tray icon (Win2k, WinXP)?
Best regards,
Eugene Pustovoyt
|
|
|
|
|
Hi all,
I have developed a dialog based application in VC++ 6.0
I have dropped a button and attached a event handler with this button.
I have created another dialog template for my child windows.
On button clicks I am calling new operator to create those MODLESS child dialogs windows.
Now when I call the Show(...) method and minimzes it, the child dilaog minimizes above the task bar rather then like normal dialog windows.
You can visualize the situation like, when we have a MDI application, and whenever we create a new view it minimizes within the MDI application rather then in the task bar.
Please anybody helps me in this regard.
The Phantom.
|
|
|
|
|
Hello!
I think I have read about ProfUIS library for C++ developer on this forum some days before, but I could not find the article this time. Could you, please, help me and give me a link to the article or any other article about ProfUIS.
Best Regards,
Haldir
|
|
|
|
|
http://www.codeproject.com/docking/prod_profuis.asp[^]
Michael
'War is at best barbarism...Its glory is all moonshine. It is only those who have neither fired a shot nor heard the shrieks and groans of the wounded who cry aloud for blood, more vengeance, more desolation. War is hell.' - General William Sherman, 1879
|
|
|
|
|
Hey all,
I need some help using SDI with formviews. I can't seem to figure out how to change the screen to a different formview.
For instance I have created two different formviews, one with a button on it, and another with just text on it to see if it will work. The problem I have is I don't know what to put in the button to make the view change resource IDD's and use the second formview. It looks like it is as simple as changing the ID, then calling invalidate to repaint the view with my new formview. Can anyone help me on this??
Thanks,
Mike
|
|
|
|
|
Not that simple, I'm afraid. You have to create the second CFormView object and perform some low-level "trickery" to swap them -- I'm sure there's an article about switching forms around here somewhere...
Steve S
|
|
|
|
|
|
Thanks a bunch. That's exactly what I was looking for.
|
|
|
|
|
Got another question for you that pertains to the question above, if you're able to answer it. A general doc/view question though.
The application I want to use the SDI for I have programmed in a dialog based interface. The reason for the switch is to create printable reports, which I don't see a way to do in dialog based.
What I'm doing is reading in tables from a database and displaying them in dialog windows, and allowing things to be entered into the database through the dialogs. The question I have is, is this something that should be used in an SDI like I'm thinking or should it be used in an MDI?
I'm still pretty new to the doc/view structure and SDI/MDI. I've only really done one program using it about a year ago during my last year of school. Anyway, I don't really need any detailed explanations or anything like that, just wondering what the best way to go is, so I don't spend my time learning something that isn't going to be useful for my project. (I do realize that MDI builds off of SDI, but if MDI is the way to go I'd rather learn how to build the multiple views using that instead of what I'm currently doing with SDI).
Thanks,
Mike
|
|
|
|
|
Hi.
I want my view support zoom in/out feature, such as Word and Visio, user can
set view scale to 400%, 200%, 100%, 50%, etc.
Currently I implement this feature by GDI mapping( MM_ANISOTROPIC ), my view
contain a workarea and some graphs( bitmap ), I change GDI mapping when user
set view zoom.
Now the problem is GDI mapping is not good when draw a bitmap, even worse
then StretchBlt. what are you think about it? or have better ways to do it.
|
|
|
|
|
well ...scaling must be done with a "scaling factor" meaning...
double scale=1;
CreatFont.withsize(12*scale) //... that will equal to 100% scaling...
scale=2;
CreatFont.withsize(12*scale) //... that will equal to 200% scaling...
scale=3;
CreatFont.withsize(12*scale) //... that will equal to 300% scaling...
everything must be done the same way ... (by a scaling factor)
bitmap scaling must be done with a generic algorithm (StrechBlt is only good in winXP)
or use GDI+
|
|
|
|
|
Hi,
Iam trying to read a file and i want to put it in buffer. Do i have to use read and write ? Are this stuff the only way or can i use filebuf? I read about this class but i dont understand at all if i can use it
Thanks
Youpie
|
|
|
|
|
Sorry i forgot to say i was trying to open a binary file and send the buffers thoughout a socket.
Thanks
Youpie
|
|
|
|
|
Mije wrote:
Do i have to use read and write ?
Are you talking about in the general sense, or are you talking about istream::read() and ostream::write() ? If the former, yes. If the latter, no.
Mije wrote:
...can i use filebuf?
filebuf::open() can be used to open a file for I/O.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hello,
I have an application where I start UI threads from time to time. The UI threads have member vars that they never change they only read..
Before I resume/start a thread I create a pointer to the thread in my main application and store the pointer in a vector. At times I need to change a threads member variable but I first need to make sure that the pointer to the thread is still valid. I'm not sure if this is the right way to do it.
if(pThread != NULL)
{ } // Change the var
Even though I check to see if the pointer is valid every now and then it crashes saying that the memory was already freed when I try to change the var.
Is this safe?
Is the if(pThread != NULL) safe? or is there a better way?
Any ideas on how I can be sure the thread is still there and will not exit while I access this member var?
Thanks,
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
No and No
1. You need some kind of locking strategy to sync the main thread and the UI threads or bad things will happen (Oh, it already does )
2. The threadhandle in the main thread doesn't "know" that a thread has exited. You need to check this. There is a sys call to get the exitstatus of the thread, it will tell you if it is still alive. There are other ways to do this aswell.
Good luck!
|
|
|
|
|
You need some kind of locking strategy to sync the main thread and the UI threads or bad things will happen
I dont think locking is required, since the UI thread is not modifying the variables.
To check whether the thread has exited or not, use GetExitCodeThread API.
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
|
|
|
|
|
If you think that accessing (reading) a variable is an atomic operation, be my guest and go ahead. Ok, some types MAY be accessed atomically but the point is: If you are asking those questions, you don't know.
|
|
|
|
|
my dear friend,
I am not the one who raised the hands. I was just giving a comment on your point!!!
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
|
|
|
|
|
I noticed that after I submitted my reply. *DOH*
Since he was talking about variables in general terms I felt that I really should stress the point that a reader/writer releationship "always" need syncronization. Those errors are hell to find otherwise.
|
|
|
|
|
Stefan Pedersen wrote:
...a reader/writer releationship "always" need syncronization.
Agreed.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Thanks for the input..
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|