| |
 |
|
|
.NET DotNet Forum Index » Visual C++ Forum » exit a function()...
Page 1 of 1
|
| Author |
Message |
| SteveDB1... |
Posted: Fri Jul 04, 2008 12:20 am |
|
|
|
Guest
|
Hi all.
I'm using VS 2008 Express C++.
I created a console application back in 1999, and updated it for VC++ 6.0 in
2001.
I've updated again this past month, and have found enough differences that I
now need to use a different exit routine.
In 2001, I could use a basic escape with a do {}while(ch!= 27);
Now that apparently does not work.
So, how do I exit a function now with C++ 2008 express?
My general form is:
------------------------------------------------------------------
# include "stdafx.h"
# include <iostream>
# include <cmath>
# include <xutility>
# include <stdlib.h>
# include <cctype>
# include <conio.h>
# define PI 3.1415926535898
int n;
int ParA, ParB, ParC, ParD, ParE;
using namespace std;
int functionA (int& ParA, int& ParB, int& ParC, int& ParD)
//ParA through ParE are parameters/variables (please pardon me if I
//incorrectly stated the terms) within my functions.
{
secondary menu to explain how to use this function-A.
do
{
core code for this function.
} while (ch_n != 27);
//return n; //where n is an equation within the core code.
exit(0);
}
int functionB (int& ParA, int& ParB, int& ParC, int& ParD, int& ParE);
secondary menu to explain how to use this function-B.
do
{
core code for this function.
} while (ch_(n+1) != 27);
//the "ch_(n+1) is a character subscript I used for my while escape.
//return n; //where n is an equation within the core code.
exit(0); //this does not work to exit my functions.
}
int functionC (int& ParA, int& ParB);
secondary menu to explain how to use this function-C.
do
{
core code for this function.
} while (ch_(n+2) != 27);
//return n; //where n is an equation within the core code.
exit(0);
}
int main()
{
Do
{
main welcome menu which gives options to access my functions,
or exit the program.
Switch(ch)
{
case '1' : functionA(ParA, ParB, ParC, ParD);
break;
case '2' : functionB(ParA, ParB, ParC, ParD, ParE);
break;
case '3' : functionC(ParA, ParB);
break;
default : exit(0);
}
} while (ch != 27);
} |
|
|
| Back to top |
|
| Mark Salsbery [MVP]... |
Posted: Sat Jul 05, 2008 1:36 pm |
|
|
|
Guest
|
"SteveDB1" <SteveDB1 at (no spam) discussions.microsoft.com> wrote in message
news:8C3B1690-E420-44AE-924E-BF52EED37061 at (no spam) microsoft.com...
Quote: Hi all.
I'm using VS 2008 Express C++.
I created a console application back in 1999, and updated it for VC++ 6.0
in
2001.
I've updated again this past month, and have found enough differences that
I
now need to use a different exit routine.
In 2001, I could use a basic escape with a do {}while(ch!= 27);
Now that apparently does not work.
So, how do I exit a function now with C++ 2008 express?
My general form is:
------------------------------------------------------------------
# include "stdafx.h"
# include <iostream
# include <cmath
# include <xutility
# include <stdlib.h
# include <cctype
# include <conio.h
# define PI 3.1415926535898
int n;
int ParA, ParB, ParC, ParD, ParE;
using namespace std;
int functionA (int& ParA, int& ParB, int& ParC, int& ParD)
//ParA through ParE are parameters/variables (please pardon me if I
//incorrectly stated the terms) within my functions.
{
secondary menu to explain how to use this function-A.
do
{
core code for this function.
} while (ch_n != 27);
//return n; //where n is an equation within the core code.
exit(0);
}
int functionB (int& ParA, int& ParB, int& ParC, int& ParD, int& ParE);
secondary menu to explain how to use this function-B.
do
{
core code for this function.
} while (ch_(n+1) != 27);
//the "ch_(n+1) is a character subscript I used for my while escape.
//return n; //where n is an equation within the core code.
exit(0); //this does not work to exit my functions.
}
int functionC (int& ParA, int& ParB);
secondary menu to explain how to use this function-C.
do
{
core code for this function.
} while (ch_(n+2) != 27);
//return n; //where n is an equation within the core code.
exit(0);
}
int main()
{
Do
{
main welcome menu which gives options to access my functions,
or exit the program.
Switch(ch)
{
case '1' : functionA(ParA, ParB, ParC, ParD);
break;
case '2' : functionB(ParA, ParB, ParC, ParD, ParE);
break;
case '3' : functionC(ParA, ParB);
break;
default : exit(0);
}
} while (ch != 27);
}
exit() is for terminating the application, not to exit a function.
To exit a function, use return.
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++ |
|
|
| Back to top |
|
| SteveDB1... |
Posted: Sat Jul 05, 2008 4:05 pm |
|
|
|
Guest
|
Mark,
Thank you for your response.
I've replaced the exit() with "return 0;"
I still have essentially the same problem- it will not allow me to exit the
function.
I can exit the program with a zero, but no keystroke of any key allows me
out of the function, and if I want to exit, I must close the program by
clicking the close 'x' at the top of the cmd console window.
I guess my initial question following the return 0 issue, would I be better
off without using the do-while since the escape key no longer allows me the
out it once did?
Again, thank you for your helps.
"Mark Salsbery [MVP]" wrote:
Quote: "SteveDB1" <SteveDB1 at (no spam) discussions.microsoft.com> wrote in message
news:8C3B1690-E420-44AE-924E-BF52EED37061 at (no spam) microsoft.com...
Hi all.
I'm using VS 2008 Express C++.
I created a console application back in 1999, and updated it for VC++ 6.0
in
2001.
I've updated again this past month, and have found enough differences that
I
now need to use a different exit routine.
In 2001, I could use a basic escape with a do {}while(ch!= 27);
Now that apparently does not work.
So, how do I exit a function now with C++ 2008 express?
My general form is:
------------------------------------------------------------------
# include "stdafx.h"
# include <iostream
# include <cmath
# include <xutility
# include <stdlib.h
# include <cctype
# include <conio.h
# define PI 3.1415926535898
int n;
int ParA, ParB, ParC, ParD, ParE;
using namespace std;
int functionA (int& ParA, int& ParB, int& ParC, int& ParD)
//ParA through ParE are parameters/variables (please pardon me if I
//incorrectly stated the terms) within my functions.
{
secondary menu to explain how to use this function-A.
do
{
core code for this function.
} while (ch_n != 27);
//return n; //where n is an equation within the core code.
exit(0);
}
int functionB (int& ParA, int& ParB, int& ParC, int& ParD, int& ParE);
secondary menu to explain how to use this function-B.
do
{
core code for this function.
} while (ch_(n+1) != 27);
//the "ch_(n+1) is a character subscript I used for my while escape.
//return n; //where n is an equation within the core code.
exit(0); //this does not work to exit my functions.
}
int functionC (int& ParA, int& ParB);
secondary menu to explain how to use this function-C.
do
{
core code for this function.
} while (ch_(n+2) != 27);
//return n; //where n is an equation within the core code.
exit(0);
}
int main()
{
Do
{
main welcome menu which gives options to access my functions,
or exit the program.
Switch(ch)
{
case '1' : functionA(ParA, ParB, ParC, ParD);
break;
case '2' : functionB(ParA, ParB, ParC, ParD, ParE);
break;
case '3' : functionC(ParA, ParB);
break;
default : exit(0);
}
} while (ch != 27);
}
exit() is for terminating the application, not to exit a function.
To exit a function, use return.
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
| Back to top |
|
| Mark Salsbery [MVP]... |
Posted: Mon Jul 07, 2008 11:47 am |
|
|
|
Guest
|
"SteveDB1" <SteveDB1 at (no spam) discussions.microsoft.com> wrote in message
news:CEC30D56-3E65-4C89-BE67-E67D962DE9BB at (no spam) microsoft.com...
Quote: Mark,
Thank you for your response.
I've replaced the exit() with "return 0;"
I still have essentially the same problem- it will not allow me to exit
the
function.
I can exit the program with a zero, but no keystroke of any key allows me
out of the function, and if I want to exit, I must close the program by
clicking the close 'x' at the top of the cmd console window.
I guess my initial question following the return 0 issue, would I be
better
off without using the do-while since the escape key no longer allows me
the
out it once did?
Again, thank you for your helps.
I'm missing something....I can't see where/how "ch" gets set or even what
type of variable it is.
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
| Back to top |
|
| SteveDB1... |
Posted: Mon Jul 07, 2008 8:35 pm |
|
|
|
Guest
|
Mark,
I apologize for that, I had only listed a basic form.
I did declare it.
char ch, ch1, ch2, ch3;
"Mark Salsbery [MVP]" wrote:
Quote: I'm missing something....I can't see where/how "ch" gets set or even what
type of variable it is.
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
| Back to top |
|
| Mark Salsbery [MVP]... |
Posted: Tue Jul 08, 2008 12:25 pm |
|
|
|
Guest
|
"SteveDB1" <SteveDB1 at (no spam) discussions.microsoft.com> wrote in message
news:D9C13954-2557-45CC-B5DB-7591659C8024 at (no spam) microsoft.com...
Quote: Mark,
I apologize for that, I had only listed a basic form.
I did declare it.
char ch, ch1, ch2, ch3;
Does it get set with _getch() ??
I don't see anything in your original code that should be different compiled
with a newer compiler.
The problem is your app isn't exiting, correct?
Using the debugger, what value for ch are you getting when you press ESC?
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
Quote:
"Mark Salsbery [MVP]" wrote:
I'm missing something....I can't see where/how "ch" gets set or even what
type of variable it is.
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
| Back to top |
|
| SteveDB1... |
Posted: Tue Jul 08, 2008 9:45 pm |
|
|
|
Guest
|
Mark,
_getchar();
I was actually using that before, and for some reason the form ( ch =
_getchar(); ) that I'd had did not work once I imported the old cpp file into
VS 2008 Express. I started posting over on a site called- Daniweb.com before
I began meandering around the newsgroups-- I didn't know that Visual Studio
had a newsgroup forum until two weeks ago, and by then I'd completely rewrote
the original code to its present form. In fact, what I originally posted that
you responded to, I pulled off a post I'd done on the same issue at Daniweb.
To be honest, I've not used the debug tool in this new program before, and
in trying it a few minutes ago, I made it as far as the main menu before it
finished. I think I was doing something wrong.
Ok, I figured out how to step over, and into specific locations. I see where
I'd missed that before.
My thinking at this point now that I've done the debug tool is that in no
previous rendition of this code did I ever have a _getchar(); within my
actual functions. I'm now wondering if I actually need this for each of my
ch_n's within the functions.
In fact, I've always used cin>> ch_n; for my function escape in the past.
I've just changed them to now be- ch_n = _getchar(); for each of my escapes.
(the _n is subscript language used in physics, for this it's just referencing
that n is a substitute for three different numbers. I.e., ch1, ch2, ch3.)
I just tried inserting a ch_n = _getchar(); in each of my functions.
Well, that didn't work. It threw 3 errors, one for each one.
Here's the error line in my output box for the third one.
e:\steve'sdocs\visual studio
2008\projects\steveangle\steveangle\steveangle.cpp(148) : error C3861:
'_getchar': identifier not found
and yes, I do have <conio.h> in my include list.
What else can I use?
Again.... I really appreciate your help.
Best.
"Mark Salsbery [MVP]" wrote:
Quote: Does it get set with _getch() ??
I don't see anything in your original code that should be different compiled
with a newer compiler.
The problem is your app isn't exiting, correct?
Using the debugger, what value for ch are you getting when you press ESC?
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++ |
|
|
| Back to top |
|
| Mark Salsbery [MVP]... |
Posted: Wed Jul 09, 2008 12:04 pm |
|
|
|
Guest
|
"SteveDB1" <SteveDB1 at (no spam) discussions.microsoft.com> wrote in message
news:93DB8967-C0E0-4AB7-99AA-C203EF69B210 at (no spam) microsoft.com...
Quote: Mark,
_getchar();
I was actually using that before, and for some reason the form ( ch =
_getchar(); ) that I'd had did not work once I imported the old cpp file
into
VS 2008 Express. I started posting over on a site called- Daniweb.com
before
I began meandering around the newsgroups-- I didn't know that Visual
Studio
had a newsgroup forum until two weeks ago, and by then I'd completely
rewrote
the original code to its present form. In fact, what I originally posted
that
you responded to, I pulled off a post I'd done on the same issue at
Daniweb.
To be honest, I've not used the debug tool in this new program before, and
in trying it a few minutes ago, I made it as far as the main menu before
it
finished. I think I was doing something wrong.
Ok, I figured out how to step over, and into specific locations. I see
where
I'd missed that before.
My thinking at this point now that I've done the debug tool is that in no
previous rendition of this code did I ever have a _getchar(); within my
actual functions. I'm now wondering if I actually need this for each of my
ch_n's within the functions.
In fact, I've always used cin>> ch_n; for my function escape in the past.
I've just changed them to now be- ch_n = _getchar(); for each of my
escapes.
(the _n is subscript language used in physics, for this it's just
referencing
that n is a substitute for three different numbers. I.e., ch1, ch2, ch3.)
I just tried inserting a ch_n = _getchar(); in each of my functions.
Well, that didn't work. It threw 3 errors, one for each one.
Here's the error line in my output box for the third one.
e:\steve'sdocs\visual studio
2008\projects\steveangle\steveangle\steveangle.cpp(148) : error C3861:
'_getchar': identifier not found
and yes, I do have <conio.h> in my include list.
What else can I use?
_getch instead of _getchar :)
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
Quote: Again.... I really appreciate your help.
Best.
"Mark Salsbery [MVP]" wrote:
Does it get set with _getch() ??
I don't see anything in your original code that should be different
compiled
with a newer compiler.
The problem is your app isn't exiting, correct?
Using the debugger, what value for ch are you getting when you press ESC?
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++ |
|
|
| Back to top |
|
| Mark Salsbery [MVP]... |
Posted: Wed Jul 09, 2008 12:08 pm |
|
|
|
Guest
|
"SteveDB1" <SteveDB1 at (no spam) discussions.microsoft.com> wrote in message
news:93DB8967-C0E0-4AB7-99AA-C203EF69B210 at (no spam) microsoft.com...
Quote: Mark,
_getchar();
I was actually using that before, and for some reason the form ( ch =
_getchar(); ) that I'd had did not work once I imported the old cpp file
into
VS 2008 Express. I started posting over on a site called- Daniweb.com
before
I began meandering around the newsgroups-- I didn't know that Visual
Studio
had a newsgroup forum until two weeks ago, and by then I'd completely
rewrote
the original code to its present form. In fact, what I originally posted
that
you responded to, I pulled off a post I'd done on the same issue at
Daniweb.
Also, this newsgroup is directed toward managed C++ (C++/CLI).
You may also want to try microsoft.public.vc.language for native C++
questions - there's lots more traffic there :-)
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
Quote:
To be honest, I've not used the debug tool in this new program before, and
in trying it a few minutes ago, I made it as far as the main menu before
it
finished. I think I was doing something wrong.
Ok, I figured out how to step over, and into specific locations. I see
where
I'd missed that before.
My thinking at this point now that I've done the debug tool is that in no
previous rendition of this code did I ever have a _getchar(); within my
actual functions. I'm now wondering if I actually need this for each of my
ch_n's within the functions.
In fact, I've always used cin>> ch_n; for my function escape in the past.
I've just changed them to now be- ch_n = _getchar(); for each of my
escapes.
(the _n is subscript language used in physics, for this it's just
referencing
that n is a substitute for three different numbers. I.e., ch1, ch2, ch3.)
I just tried inserting a ch_n = _getchar(); in each of my functions.
Well, that didn't work. It threw 3 errors, one for each one.
Here's the error line in my output box for the third one.
e:\steve'sdocs\visual studio
2008\projects\steveangle\steveangle\steveangle.cpp(148) : error C3861:
'_getchar': identifier not found
and yes, I do have <conio.h> in my include list.
What else can I use?
Again.... I really appreciate your help.
Best.
|
|
|
| Back to top |
|
| SteveDB1... |
Posted: Thu Jul 10, 2008 6:57 pm |
|
|
|
Guest
|
Hi Mark,
I thought I was in that forum.
Since Visual Studio Express 2008 C++ is what I was using, I looked all over
the place for C++, and this was what I found.
I guess I'll look more.
Thanks again for your assistance.
Best.
"Mark Salsbery [MVP]" wrote:
Quote: Also, this newsgroup is directed toward managed C++ (C++/CLI).
You may also want to try microsoft.public.vc.language for native C++
questions - there's lots more traffic there :-)
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++ |
|
|
| Back to top |
|
| Mark Salsbery [MVP]... |
Posted: Thu Jul 10, 2008 7:01 pm |
|
|
|
Guest
|
"SteveDB1" <SteveDB1 at (no spam) discussions.microsoft.com> wrote in message
news:4A78B4DC-046C-4E0C-9F67-E3C8D2F4D50A at (no spam) microsoft.com...
Quote: Hi Mark,
I thought I was in that forum.
This is "microsoft.public.dotnet.languages.vc", not
"microsoft.public.vc.language " :-)
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
Quote: Since Visual Studio Express 2008 C++ is what I was using, I looked all
over
the place for C++, and this was what I found.
I guess I'll look more.
Thanks again for your assistance.
Best.
"Mark Salsbery [MVP]" wrote:
Also, this newsgroup is directed toward managed C++ (C++/CLI).
You may also want to try microsoft.public.vc.language for native C++
questions - there's lots more traffic there :-)
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
| Back to top |
|
| SteveDB1... |
Posted: Thu Jul 10, 2008 11:10 pm |
|
|
|
Guest
|
After you told me about it, I finally found the group. It did take some
serious digging though.
Also, since you spent so much time assisting me, I thought you'd like to
know that I finally figured out what my problem was.
It turns out that one of the changes that's been made in the newer is that I
needed to place my character calls within the functions, instead of making
them globals.
Now that I've changed that, it works great-- exactly as in days of old.....
Thanks again for your spending the time.
"Mark Salsbery [MVP]" wrote:
Quote: "SteveDB1" <SteveDB1 at (no spam) discussions.microsoft.com> wrote in message
news:4A78B4DC-046C-4E0C-9F67-E3C8D2F4D50A at (no spam) microsoft.com...
Hi Mark,
I thought I was in that forum.
This is "microsoft.public.dotnet.languages.vc", not
"microsoft.public.vc.language " :-)
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
Since Visual Studio Express 2008 C++ is what I was using, I looked all
over
the place for C++, and this was what I found.
I guess I'll look more.
Thanks again for your assistance.
Best.
"Mark Salsbery [MVP]" wrote:
Also, this newsgroup is directed toward managed C++ (C++/CLI).
You may also want to try microsoft.public.vc.language for native C++
questions - there's lots more traffic there :-)
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
| Back to top |
|
| |
|
Page 1 of 1
All times are GMT - 5 Hours
The time now is Sun Sep 07, 2008 11:49 pm
|
|