Hello,
I recently just finished my C app nothing special just a little app for personal use but when I press ENTER the command box disappears and my program just exits before it has done anything.I am running a Xp Home OS
Also I am using a IDE enviroment is this the best way.
10 4720
What is the program supposed to do? Is it supposed to output something, or does it just work in the background? If it just works in the background, did you check to see if it actually performed its function?
What is the program supposed to do? Is it supposed to output something, or does it just work in the background? If it just works in the background, did you check to see if it actually performed its function?
Basically its a simple program which outputs 6 random numbers but you press ENTER and it just disappears no random numbers appear
Can i see the code from your main() function?
Can i see the code from your main() function?
Yeh sure: - int main()
-
-
{
-
int numbers[RANGE]; //Array that holds the balls
-
int i,b;
-
unsigned long d; //Delay Variable
-
-
printf("LOTTO PICKER\n");
-
-
seedrnd();
-
-
/*Initialize the array*/
-
-
for(i=0;i<RANGE;i++)
-
numbers[i]=0;
-
-
printf("Press ENTER to pick this weeks LOTTO numbers");
-
getchar();
-
-
/*Draw the numbers*/
-
-
printf("\nHere they come: ");
-
for(i=0;i<BALLS;i++)
-
{
-
for(d=0;d<=DELAY;d++); //Pause Here
-
-
/*Picks a random numbers and checks to see whether
-
it has already been picked*/
-
-
do
-
{
-
b=rnd(RANGE); //Draw Number
-
}
-
while(numbers[b]);
-
-
numbers[b]=1;
-
printf("%i ",b+1);
-
}
-
-
printf("\n\nGood luck in the draw!\n");
-
}
-
-
/* Generate a random value */
-
-
int rnd(int range)
-
{
-
int r;
-
-
r=rand()%range;
-
return(r);
-
}
-
-
-
void seedrnd(void)
-
{
-
srand((unsigned)time(NULL));
-
}
-
Yeh sure: - int main()
-
-
{
-
int numbers[RANGE]; //Array that holds the balls
-
int i,b;
-
unsigned long d; //Delay Variable
-
-
printf("LOTTO PICKER\n");
-
-
seedrnd();
-
-
/*Initialize the array*/
-
-
for(i=0;i<RANGE;i++)
-
numbers[i]=0;
-
-
printf("Press ENTER to pick this weeks LOTTO numbers");
-
getchar();
-
-
/*Draw the numbers*/
-
-
printf("\nHere they come: ");
-
for(i=0;i<BALLS;i++)
-
{
-
for(d=0;d<=DELAY;d++); //Pause Here
-
-
/*Picks a random numbers and checks to see whether
-
it has already been picked*/
-
-
do
-
{
-
b=rnd(RANGE); //Draw Number
-
}
-
while(numbers[b]);
-
-
numbers[b]=1;
-
printf("%i ",b+1);
-
}
-
-
printf("\n\nGood luck in the draw!\n");
-
}
-
-
/* Generate a random value */
-
-
int rnd(int range)
-
{
-
int r;
-
-
r=rand()%range;
-
return(r);
-
}
-
-
-
void seedrnd(void)
-
{
-
srand((unsigned)time(NULL));
-
}
-
Have you tried putting some sort of "press enter to continue" catch at the end? A scanf() statement that you just exit after to keep the console (output) window open?
Have you tried putting some sort of "press enter to continue" catch at the end? A scanf() statement that you just exit after to keep the console (output) window open?
How would I go about doing it its just that my class have only just started C and we had this project to write our own C program so my knowledge on this is very slim.
Thanks
How would I go about doing it its just that my class have only just started C and we had this project to write our own C program so my knowledge on this is very slim.
Thanks
Just stick a getchar() (like in line 18 above) above your return 0;.
(This could also be a scanf(), or other method that reads from standard input.)
Thanks alot its fully working now.
Thanks again
Thanks alot its fully working now.
Thanks again
Great! Please post again if you run into another issue.
You wouldn't be using Visual Studio.NET by any chance???
If not stop reading here.
The default build for Visual Studio is debug. That is, code is put in your .exe to support the debugger. When you select Start, Visual Studio sees the debug code and just runs the program on the assumption that you have inserted necessary pauses, like breakpoints.
However, you can select Start Without Debugging. In this case, Visual Studio sees the debug code but understands that you are not using your debugger. So after main() completes, it pauses execution with Press any key to continue.... No need to add phony stops in your code.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: MLH |
last post by:
I am having failures processing the following command and I wonder
if you can tell me what I must do in order to have success. When I try
to run source mysql_dump.sql.txt ==> it is a problem...
|
by: Peter A. Schott |
last post by:
Per subject - I realize I can copy/paste a line at a time into an interactive
session when I'm trying to debug, but was wondering if there is any tool out
there that allows me to copy sections of...
|
by: Carlo Marchesoni |
last post by:
I have a UserControl that builds a Tree-View Menu using Javascript. This UC does not run as a ServerControl
Then, in every aspx page I include this UC. Everything works perfect, except that if I...
|
by: Jay Feldman |
last post by:
I've seen some messages about the screen flashing black for a few moments when executing a program in vb.net
this may be because the command prompt settings were changed.
when the command prompt...
|
by: Ennio-Sr |
last post by:
Hi all!
I'm writing a script that presents the user with a numbered lines
menu, each line corresponding to a <case n> which executes a psql
command. As the psql-commands are very similar to each...
|
by: Simon |
last post by:
Hi all... I've got an editable datagrid in my application. Clicking
"edit" enables those fields to be editted, and then clicking Update triggers
my code to do the update on the database. I...
|
by: poolshark1691 |
last post by:
Just joined and am learning c++, i have got a compiler, i run the
executable, i get the DOS command prompt showing me my program but once
it gets to the "return 0;" part of the code, basically the...
|
by: Camellia |
last post by:
Hi all,
I'll get straight into it.
When I try to run the code:
.....
while (scanf("%c", &c) == 1)
printf("%c", c);
.....
I input "abcd" follows by an EOF(Ctrl + d) instead of pressing...
|
by: Camellia |
last post by:
Hi all,
I'll get straight into it.
When I try to run the code:
.....
while (scanf("%c", &c) == 1)
printf("%c", c);
.....
I input "abcd" follows by an EOF(Ctrl + d) instead of pressing...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |