Would you like to react to this message? Create an account in a few clicks or log in to continue.

Terminating NULL

2 posters

 :: C Languages :: C++ :: Help!

Go down

Terminating NULL Empty Terminating NULL

Post  David B Mon Aug 01, 2011 2:16 pm

How do you add a terminating NULL to the end of a C++ program?
David B
David B
Administrator
Administrator

Posts : 618
Join date : 2011-07-20
Location : The Twilight Zone!

https://programmingforums.forumotion.com/

Back to top Go down

Terminating NULL Empty Re: Terminating NULL

Post  legolizard Mon Aug 01, 2011 2:25 pm

I don't quite understand what you mean. Do you want your program to just terminate or end at some specific line? If so then there are a few ways to do so

Here are the ways that I commonly use:

1)Call for a system command, system(); and within the parenthesis pass in a string parameter,"PAUSE." So that you get:

system("PAUSE");

This command should be put at the end of your main(). Now there are many problems with using the system(), so I don't recommend using it for large programs. For largrer programs you should include a separate library called conio.h and use the function getch(); before "return 0;" at the end of your main() which is much better for a variety of reasons.

#include <conio.h>

int main()
{
//Some code

getch();
return 0;
}
legolizard
legolizard

Posts : 137
Join date : 2011-08-01
Location : On planet Char.

Back to top Go down

Terminating NULL Empty Re: Terminating NULL

Post  David B Tue Aug 02, 2011 8:11 am

legolizard wrote:I don't quite understand what you mean. Do you want your program to just terminate or end at some specific line? If so then there are a few ways to do so

Here are the ways that I commonly use:

1)Call for a system command, system(); and within the parenthesis pass in a string parameter,"PAUSE." So that you get:

system("PAUSE");

This command should be put at the end of your main(). Now there are many problems with using the system(), so I don't recommend using it for large programs. For largrer programs you should include a separate library called conio.h and use the function getch(); before "return 0;" at the end of your main() which is much better for a variety of reasons.

#include

int main()
{
//Some code

getch();
return 0;
}
No. I mean is there a way to return a NULL? I want to return a NULL, but I don't know how in C++.
David B
David B
Administrator
Administrator

Posts : 618
Join date : 2011-07-20
Location : The Twilight Zone!

https://programmingforums.forumotion.com/

Back to top Go down

Terminating NULL Empty Re: Terminating NULL

Post  legolizard Tue Aug 02, 2011 11:07 am

Well sort of. You see there are two basic groups of functions in C++, functions that do not return anything such as as void functions and constructors and then you have functions that must return something, preferably one that matches the type of function. For example, the main() must always return 0 because the main() is of integer type and well zero is an integer, this is why we have the keyword return at the bottom. Now NULL by definition means nothing so technically void functions return null, however you never ever go :return NULL, because they do so automatically.
legolizard
legolizard

Posts : 137
Join date : 2011-08-01
Location : On planet Char.

Back to top Go down

Terminating NULL Empty Re: Terminating NULL

Post  David B Tue Aug 02, 2011 3:34 pm

legolizard wrote:Well sort of. You see there are two basic groups of functions in C++, functions that do not return anything such as as void functions and constructors and then you have functions that must return something, preferably one that matches the type of function. For example, the main() must always return 0 because the main() is of integer type and well zero is an integer, this is why we have the keyword return at the bottom. Now NULL by definition means nothing so technically void functions return null, however you never ever go :return NULL, because they do so automatically.
Okay! Thanks for the help!.
David B
David B
Administrator
Administrator

Posts : 618
Join date : 2011-07-20
Location : The Twilight Zone!

https://programmingforums.forumotion.com/

Back to top Go down

Terminating NULL Empty Re: Terminating NULL

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top


 :: C Languages :: C++ :: Help!

 
Permissions in this forum:
You cannot reply to topics in this forum