|
-
December 7th, 2004, 07:36 PM
#1
_ENDing a program...
Hello:
I have been researching how to end a program, giving the user an opportunity to end the program, or myself in the coding process via a FOR loop to do so. I have found examples involving "end" and "_end" or "cend" (?) but am unsure how to implement it correctly, what it will do exactly, and when it will do it. I need to integrate this into my code. Please explain with a commented ( //--) example if possible...
Thank-you in advance,
Mansoor
"Nay, you love this present life!"
Save your keystrokes!
-
December 7th, 2004, 07:51 PM
#2
Re: _ENDing a program...
I think you are looking for exit(). It terminates your program when called.
Code:
int main()
{
for(int i = 0; i < 100; ++i)
{
if(i == 50) exit(0); // Terminates your program when i reaches 50
}
return 0;
}
-
December 7th, 2004, 08:15 PM
#3
-
December 7th, 2004, 11:14 PM
#4
Re: _ENDing a program...
A little modified version can be like
Code:
char szText[128] = {0};
for (int i = 1; i < 10000; i++) // A long loop
{
sprintf(szText , "%d) Hello World\n" , i++);
printf(szText);
if (kbhit())
{
char key = _getch();
if ('q' == key)
break;
}
}
Here, the loop will be terminated, if it gets complete or user press "q" key.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|