|
-
Mar 9th, 2001, 11:03 AM
#1
Thread Starter
Addicted Member
Can someone tell me what this means.
I see it in alot of programs.
The part I am confused on is the
if((argc<2) || (argc>3))
{ proceed w. code
Why do they put that at the beginning of code ?
Code:
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void main(int argc, char *argv[])
{
unsigned char car, dump;
FILE *in, *out;
long int i, perc, cont;
i=1;
perc=1;
cont=0;
if ((argc<2) || (argc>3))
{
Thanks
-
Mar 9th, 2001, 12:59 PM
#2
Monday Morning Lunatic
It means that argc must be either 2 or 3.
|| == Logical OR
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 9th, 2001, 02:26 PM
#3
A high level answer is that they are testing to see if 2 and only 2 parameters were passed in on the command line to start the app.
app arg1 arg2
as opposed to:
app
app arg1
app arg1 arg2 arg3
app arg1 arg2 arg3 argN etc.
-
Mar 9th, 2001, 02:30 PM
#4
Monday Morning Lunatic
It's >3 so 3 is acceptable...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 9th, 2001, 02:58 PM
#5
Thread Starter
Addicted Member
See I understand all of that,
What I dont understand is what arguments are passed at the beginning.,
I never knew arguments where passed right when the main function is hit.
The user has no controll over those arguments , so what is the point of them.
-
Mar 9th, 2001, 03:14 PM
#6
Monday Morning Lunatic
Ah...but the user does 
argv[0] is always the location of the program. The rest of the array up to index (argc-1) are the arguments passed on the command line:
argv[0] = "c:\programs\myprog.exe"
argv[1] = "arg1"
argv[2] = "arg2"
argc = 3
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 9th, 2001, 05:45 PM
#7
Yeah, I miscounted. They want either:
app arg1
or
app arg1 arg2
Is that right parksie?
Help
The user has no controll over those arguments , so what is the point of them.
The user enters either "arg1" or "arg1 arg2" when launching "app".
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
|