By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,233 Members | 1,972 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,233 IT Pros & Developers. It's quick & easy.

The Command Prompt

P: 76
I did a little fun program in C++ for the guys at work that picks random numbers for their Nascar pool. The random numbers are printed each on a new line and it always goes over the default viewing area which is annoying to me.

Is there something like the SetWindowPos function for the command prompt?

If I could give it some coordinates to follow when executed or even have the window go full screen.

Thanks-a-bunch,
James
Jun 6 '07 #1
Share this Question
Share on Google+
7 Replies


sicarie
Expert Mod 2.5K+
P: 4,677
Just to clarify - you are trying to resize the console window that the random numbers are output to?

What is your OS?
Jun 6 '07 #2

AdrianH
Expert 100+
P: 1,251
Hazerding a guess, I'd say it is Windoze given the reference to SetWindowPos().

At the command line, type start /?. I think that is what you are looking for.


Adrian
Jun 7 '07 #3

P: 76
This is just a plain C++ command prompt program. Nothing special. I was just asking about the SetWindowPos because its the closest thing I could find to solve the problem. SetWindowPos works for windows applications only I think.

Found this in an old C for Dummies book from a long time ago. Works well enough but I question the randomness of the random numbers.

Here's the code.
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>    
  4.  
  5. #define DRIVERS 43    
  6. #define PICKS 43        
  7. #define DELAY 1000000    
  8.  
  9.  
  10. int rnd(int range);
  11. void seedrnd(void);
  12.  
  13. void main()
  14. {
  15.     int numbers[DRIVERS];    
  16.     int i,b;
  17.     unsigned long d;    
  18.  
  19.     printf("  N A S C A R  P O O L \nSRANDOM NUMBER GENERATOR\n\n");
  20.     seedrnd();        
  21.  
  22. /* initialize the array */
  23.  
  24.     for(i=0;i<DRIVERS;i++)    
  25.         numbers[i]=0;
  26.  
  27.     printf("Press Enter to pick this week's numbers:");
  28.     getchar();
  29.  
  30. /* draw the numbers */
  31.     printf("\nHere they come: \n\n\n");
  32.     for(i=0;i<PICKS;i++)
  33.     {
  34.         for(d=0;d<=DELAY;d++);    
  35.  
  36. /* picks a random number and check to
  37. see if it's already been picked */
  38.  
  39.         do
  40.         {
  41.             b=rnd(DRIVERS);    
  42.         }
  43.         while(numbers[b]);    
  44.  
  45.         numbers[b]=1;        
  46.         printf("%i \n",b+1);    
  47.     }
  48.     printf("\n\nGood luck in the drawing!\n");
  49.     printf("\n\nPress the enter key to exit.\n");
  50.     getchar();
  51.  
  52. }
  53.  
  54. /* Generate a random value */
  55.  
  56. int rnd(int range)
  57. {
  58.     int r;
  59.  
  60.     r=rand()%range;        //spit up random num.
  61.     return(r);
  62. }
  63.  
  64. /* Seed the randomizer */
  65.  
  66. void seedrnd(void)
  67. {
  68.     srand((unsigned)time(NULL));
  69. }
  70.  
Jun 7 '07 #4

100+
P: 208
This is just a plain C++ command prompt program. Nothing special. I was just asking about the SetWindowPos because its the closest thing I could find to solve the problem. SetWindowPos works for windows applications only I think.

Found this in an old C for Dummies book from a long time ago. Works well enough but I question the randomness of the random numbers.

Here's the code.
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>    
  4.  
  5. #define DRIVERS 43    
  6. #define PICKS 43        
  7. #define DELAY 1000000    
  8.  
  9.  
  10. int rnd(int range);
  11. void seedrnd(void);
  12.  
  13. void main()
  14. {
  15.     int numbers[DRIVERS];    
  16.     int i,b;
  17.     unsigned long d;    
  18.  
  19.     printf("  N A S C A R  P O O L \nSRANDOM NUMBER GENERATOR\n\n");
  20.     seedrnd();        
  21.  
  22. /* initialize the array */
  23.  
  24.     for(i=0;i<DRIVERS;i++)    
  25.         numbers[i]=0;
  26.  
  27.     printf("Press Enter to pick this week's numbers:");
  28.     getchar();
  29.  
  30. /* draw the numbers */
  31.     printf("\nHere they come: \n\n\n");
  32.     for(i=0;i<PICKS;i++)
  33.     {
  34.         for(d=0;d<=DELAY;d++);    
  35.  
  36. /* picks a random number and check to
  37. see if it's already been picked */
  38.  
  39.         do
  40.         {
  41.             b=rnd(DRIVERS);    
  42.         }
  43.         while(numbers[b]);    
  44.  
  45.         numbers[b]=1;        
  46.         printf("%i \n",b+1);    
  47.     }
  48.     printf("\n\nGood luck in the drawing!\n");
  49.     printf("\n\nPress the enter key to exit.\n");
  50.     getchar();
  51.  
  52. }
  53.  
  54. /* Generate a random value */
  55.  
  56. int rnd(int range)
  57. {
  58.     int r;
  59.  
  60.     r=rand()%range;        //spit up random num.
  61.     return(r);
  62. }
  63.  
  64. /* Seed the randomizer */
  65.  
  66. void seedrnd(void)
  67. {
  68.     srand((unsigned)time(NULL));
  69. }
  70.  

By C++ do you mean C? I've written a very similar program in C.
Jun 7 '07 #5

AdrianH
Expert 100+
P: 1,251
This is just a plain C++ command prompt program. Nothing special. I was just asking about the SetWindowPos because its the closest thing I could find to solve the problem. SetWindowPos works for windows applications only I think.

Found this in an old C for Dummies book from a long time ago. Works well enough but I question the randomness of the random numbers.

Here's the code.
Is there another question here? I've looked at the start command and discovered that it only allows you to maximise the window. If you want something else, you will have to execute a .lnk file which has the appropriate properties set.
To create and set one up:
  1. right click and drag your executable, then release.
  2. Then rename it to what you want.
  3. Right click on it and set the properties to that which you want.
  4. from your app, execute the file name though the cmd programme. Don't forget to append .lnk extention to it. I.e.
    Expand|Select|Wrap|Line Numbers
    1. system("cmd /c myexe.lnk");
Hope this helps.


Adrian
Jun 7 '07 #6

P: 79
If I got you correctly, the console window isn't large enough to hold all the numbers? In that case, there is a way to change that and keep it simple.

When the console pops up, click the upper left corner and go to Properties.

Click the Layout tab

At the "screen buffer size" field, type in however many lines you want in the Height field.

Click OK and Save properties.

It gets the work done without any unnecessary coding.
Jun 7 '07 #7

P: 76
I got it to work using the properties dialog for the executable. I would have thought their would be some piece of C code that would do it though.

Thank You for all your ideas.
Jun 12 '07 #8

Post your reply

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