473,405 Members | 2,444 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,405 software developers and data experts.

Command box disappears after pressing Enter in C Program

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.
Sep 25 '07 #1
10 4720
sicarie
4,677 Expert Mod 4TB
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?
Sep 25 '07 #2
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
Sep 25 '07 #3
sicarie
4,677 Expert Mod 4TB
Can i see the code from your main() function?
Sep 25 '07 #4
Can i see the code from your main() function?
Yeh sure:

Expand|Select|Wrap|Line Numbers
  1. int main()
  2.  
  3. {
  4.     int numbers[RANGE]; //Array that holds the balls
  5.     int i,b;
  6.     unsigned long d; //Delay Variable
  7.  
  8.     printf("LOTTO PICKER\n");
  9.  
  10.     seedrnd();
  11.  
  12.     /*Initialize the array*/
  13.  
  14.     for(i=0;i<RANGE;i++)
  15.     numbers[i]=0;
  16.  
  17.     printf("Press ENTER to pick this weeks LOTTO numbers");
  18.     getchar();
  19.  
  20.     /*Draw the numbers*/
  21.  
  22.     printf("\nHere they come: ");
  23.     for(i=0;i<BALLS;i++)
  24.     {
  25.         for(d=0;d<=DELAY;d++);  //Pause Here
  26.  
  27.         /*Picks a random numbers and checks to see whether
  28.         it has already been picked*/
  29.  
  30.         do
  31.         {
  32.             b=rnd(RANGE); //Draw Number
  33.         }
  34.         while(numbers[b]);
  35.  
  36.         numbers[b]=1;
  37.         printf("%i ",b+1);
  38.     }
  39.  
  40.     printf("\n\nGood luck in the draw!\n");
  41. }
  42.  
  43. /* Generate a random value */
  44.  
  45. int rnd(int range)
  46. {
  47.     int r;
  48.  
  49.     r=rand()%range;
  50.     return(r);
  51. }
  52.  
  53.  
  54. void seedrnd(void)
  55. {
  56.     srand((unsigned)time(NULL));
  57. }
  58.  
Sep 25 '07 #5
sicarie
4,677 Expert Mod 4TB
Yeh sure:

Expand|Select|Wrap|Line Numbers
  1. int main()
  2.  
  3. {
  4.     int numbers[RANGE]; //Array that holds the balls
  5.     int i,b;
  6.     unsigned long d; //Delay Variable
  7.  
  8.     printf("LOTTO PICKER\n");
  9.  
  10.     seedrnd();
  11.  
  12.     /*Initialize the array*/
  13.  
  14.     for(i=0;i<RANGE;i++)
  15.     numbers[i]=0;
  16.  
  17.     printf("Press ENTER to pick this weeks LOTTO numbers");
  18.     getchar();
  19.  
  20.     /*Draw the numbers*/
  21.  
  22.     printf("\nHere they come: ");
  23.     for(i=0;i<BALLS;i++)
  24.     {
  25.         for(d=0;d<=DELAY;d++);  //Pause Here
  26.  
  27.         /*Picks a random numbers and checks to see whether
  28.         it has already been picked*/
  29.  
  30.         do
  31.         {
  32.             b=rnd(RANGE); //Draw Number
  33.         }
  34.         while(numbers[b]);
  35.  
  36.         numbers[b]=1;
  37.         printf("%i ",b+1);
  38.     }
  39.  
  40.     printf("\n\nGood luck in the draw!\n");
  41. }
  42.  
  43. /* Generate a random value */
  44.  
  45. int rnd(int range)
  46. {
  47.     int r;
  48.  
  49.     r=rand()%range;
  50.     return(r);
  51. }
  52.  
  53.  
  54. void seedrnd(void)
  55. {
  56.     srand((unsigned)time(NULL));
  57. }
  58.  
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?
Sep 25 '07 #6
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
Sep 26 '07 #7
sicarie
4,677 Expert Mod 4TB
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.)
Sep 26 '07 #8
Thanks alot its fully working now.

Thanks again
Sep 26 '07 #9
sicarie
4,677 Expert Mod 4TB
Thanks alot its fully working now.

Thanks again
Great! Please post again if you run into another issue.
Sep 26 '07 #10
weaknessforcats
9,208 Expert Mod 8TB
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.
Sep 26 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

4
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...
8
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...
2
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...
1
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...
1
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...
1
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...
5
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...
9
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
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
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...
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
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...
0
isladogs
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...

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.