Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to pass command line arguments?? 2

Status
Not open for further replies.

ssudha17

Programmer
Feb 20, 2001
21
0
0
US
I am new to Borland...Have worked on Unix only...Please let me know how to pass command line arguments in Borland C++. Urgent.
Rgds,
Sudha Visit to know more about me
 
It should be the same way as in Unix . . . for example:
Code:
int main(int argc, char *argv[])
{
.
.
.
}
Argc is the number of arguments being passed to the program and argv is the pointer to the arguments.

James P. Cottingham
 
Hi!

you declare your entry point in the usual fashion:

int main (int argc, char **argv) for console apps;
int OwlMain (int argc, char **argv) if you use the OWL framework;
etc...

You can transmit the argument from the DOS command line, the same way you do from UNIX terminal;

Or you can also (and that's maybe the point of your question?) transmit the arguments from Borland C++ EDI.

To do so, you have to look in either Options->Project or Options->Environment (sorry, I cannot remember right now since I don't have BCW available). There is one edit box somewhere there that allows you to explicitly write down you arguments. It saves you the trouble of opening a DOS shell.

Don't forget to erase the arguments from the edit box after use, because as far as I remember BCW will not erase it automatically, and all subsequent program launches will be done with the same arguments.



Hope it helps!

Woliwol




 
Here a short example:

//---------------------------------------------------------------------------
int main(int argc, char **argv)
{
int n;

int done;

struct tm *tms,tm1,tm2;
time_t timer,timer1;
struct ffblk ffblk;
int cday,cmon,cyy,diff,td,tmo,tyy,diffm,diffy;
int day,mon,yy;
char text[256];
char path[256],drive[4],dir[256],name[256],ext[4];
n=argc; //Number of Arguments
if(n!=3)
{
printf("Falsche Anzahl von Argumenten : %d\n",n);
scanf("%c",&text[0]);
exit(2);
}
*argv++; // the first Argument is not needed (Loadfile)
strcpy(text,*argv++); // argument is String
diff=atoi(*argv); // Argument is Integer


hnd
hasso55@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top