|
-
Mar 4th, 2002, 03:20 PM
#1
Thread Starter
Junior Member
-
Mar 4th, 2002, 04:16 PM
#2
Fanatic Member
You should use the function atoi from stdlib.h, to read the menu number.
int menunumber = atoi(argv[1]);
-
Mar 4th, 2002, 05:11 PM
#3
Thread Starter
Junior Member
Hi there riis, I tried that code you posted - thank you. I got my program going from the command prompt and it passed the value as it should do, although to get it working I had to comment out a line which said cin >> menunumber; . When I tried to run the program in the development environment ( Visual C++ 6 ) the program just hangs. I assume this is because the program expects a value to be passed as a string from the command prompt and when it doesn't get a value it can't assign anything to the variable 'menunumber'.
Is there a way of saying something like:
IF no value has been passed via the command prompt then menunumber=0; and read the number from the keyboard the value the user inputs ??
How also can I get the program to ignore the cin >> menunumber; statement when passing a value via the command prompt?
This would enable my program to work both from the command prompt and the development environment would it?
Cheers
CaptainChainsaw
-
Mar 5th, 2002, 07:42 AM
#4
The argument named argc is the number of arguments passed to the app. It is always at least 1 (the program name itself), so you can test if it is greater than 1 and if yes, get the item number. Else get input from the user.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|