Fwd: int question
Fwd: int question
- Subject: Fwd: int question
- From: email@hidden
- Date: Wed, 6 Jun 2001 22:03:28 -0400
Sent this out with an unregistered email address last night, sorry.
Begin forwarded message:
>
>
>
Here are a couple of useful links i hope,
>
>
>
http://www.whitefang.com/unix/faq_toc.html
>
http://www.strath.ac.uk/CC/Courses/NewCcourse/ccourse.html
>
http://www.cis.ohio-state.edu/hypertext/faq/usenet/C-faq/top.html
>
>
Also, Deitel and Deitel Learn to Program series is pretty good for
>
learning C,C++,Java
>
Then you can move on to more platform specific stuff.
>
>
>
And ( my understanding is)
>
>
int main (int argc, const char * argv[])
>
>
argc is an integer representing the number of command line parameters
>
argv is an array holding null terminated strings with the arguments.
>
>
What happens in on the operating system when the "shell" is called to
>
create a process and initializes and calls the
>
c runtimes etc, it passes these parameters to the entry point (main) of
>
the application.
>
>
so for example i could do this:
>
>
>
>
int main(int argc, char * argv[])
>
{
>
>
>
switch( argc)
>
{
>
>
>
>
>
>
case 5:
>
//man all these arguments, if this where real, i'd have to
>
validate them all;)
>
strcpy(szArg1,argv[1]);
>
>
//second argument is a number
>
nArg2 = atoi( argv[2] );
>
>
//ditto
>
nArg3 = atoi( argv[3] );
>
>
//third is a long
>
lArg4 = atol(argv[4]);
>
>
>
>
>
break;
>
>
case 2:
>
case 3:
>
case 4:
>
default:
>
>
printf("Usage: Hey man, you did not pass enough stuff.........\n");
>
printf("youhavetobekiddingUnixCLIApp [a string] [a
>
number] [ a number] [a bigger number]\n");
>
>
return (0);
>
>
}
>
>
>
////////////Please do not flame the lameness of this example :)////
>
>
Alot of folks have a dedicated function that parses the command line
>
too.
>
>
Hope this helps.
>
>
A man, A Plan, A Canal, Panama