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

command line arguments

P: 3
Hi

I have made a command line tool which converts a particular log file in .bin format to a text file.
But as of now the names of these files are hardcoded i.e it converts log.bin to log.txt.
Here is the function call

int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{

ConvertDatalogToText( "log.bin", "log.txt",
"dump.txt", true );
return 0;

}

I concerned with the first three files
It picks up log.bin from the directory and using a dump.txt file in the same dir it generates the text file with name log.txt.
Thus if i use this tool like this -
> Convert.exe log.bin dump.txt
This works fine and log.txt is generated.

However i now Want that i should not have any limitation on the names. i.e Whatever *.bin argument is given in the command line tool should be picked up , also same name should be used for the text file.
for e.g if i give
> Convert.exe sample_log.bin new_dump.txt
then it should pick up the file name sample_log.bin and new_dump.txt from the dir and generate sample_log.txt


Also , for more information
LPTSTR lpCmdLine argument of AfxWinMain function has the following definition
typedef LPSTR LPTSTR;
typedef CHAR *LPSTR ;
Thus LPTSTR is just a char pointer.



Right now the file names are hardcoded as shown in the function call above.
Please help me remove this restriction.

Thanks in advance

Regards
Nikhil
Dec 20 '06 #1
Share this Question
Share on Google+
1 Reply


Banfa
Expert Mod 5K+
P: 8,916
That is easy really, LPTSTR lpCmdLine points to the command line of your program when it is executed. All you need to do is split that command line in it's various arguments and then us them as required.

look up strtok, this will help you split the command line into multiple arguments.
Dec 20 '06 #2

Post your reply

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