473,394 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

exit a function()

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);
}

Jul 4 '08 #1
11 2243
"SteveDB1" <St******@discussions.microsoft.comwrote in message
news:8C**********************************@microsof t.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++


Jul 5 '08 #2
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:
"SteveDB1" <St******@discussions.microsoft.comwrote in message
news:8C**********************************@microsof t.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++

Jul 5 '08 #3


"SteveDB1" <St******@discussions.microsoft.comwrote in message
news:CE**********************************@microsof t.com...
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++
>

Jul 7 '08 #4
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:
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++

Jul 8 '08 #5
"SteveDB1" <St******@discussions.microsoft.comwrote in message
news:D9**********************************@microsof t.com...
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++

>

"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++
>

Jul 8 '08 #6
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.hin my include list.

What else can I use?
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++
Jul 9 '08 #7


"SteveDB1" <St******@discussions.microsoft.comwrote in message
news:93**********************************@microsof t.com...
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.hin my include list.

What else can I use?

_getch instead of _getchar :)

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++

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++
Jul 9 '08 #8
"SteveDB1" <St******@discussions.microsoft.comwrote in message
news:93**********************************@microsof t.com...
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++

>
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.hin my include list.

What else can I use?
Again.... I really appreciate your help.
Best.


Jul 9 '08 #9
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:

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++
Jul 11 '08 #10
"SteveDB1" <St******@discussions.microsoft.comwrote in message
news:4A**********************************@microsof t.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++
Jul 11 '08 #11
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:
"SteveDB1" <St******@discussions.microsoft.comwrote in message
news:4A**********************************@microsof t.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++
Jul 11 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Alex | last post by:
I am trying to write an Exit module for the Certification server in VB.NET and I cant get the module to be recognised by the Certification MMC snap in. Its function is to capture Serial Numbers of...
32
by: Protoman | last post by:
I have a function that calculates the mean of the some numbers; I need it to accept any number of parameters (one needs to be the number of the other parameters) Can you help me out here? Here's...
7
by: Darklight | last post by:
if the exit() function is contained in stdlid.h why if i remove the above header file the exit function still works and i can still compile program without any error messages using cc file.c if i...
17
by: jwaixs | last post by:
Hello, I was wondering, what's the difference between exit and return in the main() function? For me they both look the same, or aren't they? And if they aren't, which should I use in which...
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
3
by: darrel | last post by:
This might be a really dumb question, but when should/shouldn't one use the exit function command? If I have this: function() if something then do this return that else
20
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main function? Can a function call (or only this...
16
by: Laurent Deniau | last post by:
I would like to know if the use of the pointer ref in the function cleanup() below is valid or if something in the norm prevents this kind of cross-reference during exit(). I haven't seen anything...
39
by: mathieu | last post by:
Hi there, I am trying to reuse a piece of code that was designed as an application. The code is covered with 'exit' calls. I would like to reuse it as a library. For that I renamed the 'main'...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.