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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using command line arguments

Status
Not open for further replies.

Cbasic

Programmer
Aug 26, 1999
4
US
How do you:<br>
<br>
Write a program that accepts several arguments from the command line and based on these arguments perform none or several different operations on the specified input file.<br>
<br>
For eg.<br>
<br>
A command such as:- "Comline.exe inputfilename.ext outputfilename [/v /u /s]"<br>
<br>
/v - Counts the amount of vowels in the text file<br>
<br>
/u - Converts the entire text file to capitals letters<br>
<br>
/s - Sorts the words(including numbers and special characters) of the input file in alphabetical order and save the sorted version in a file called "result.s".<br>
<br>
The program should also produce three output files:<br>
/v - result.v<br>
/u - result.u<br>
/s - result.s
 
No is it not a college assignment but I presently doing a course for the job I am presently working at. Can you help me??????? Please!!!
 
About 90% of the stuff you need to know to do this is covered in the book "The C Programming Language" by Kernigan and Richie. That should sort you out.<br>
<br>
Could I suggest you treat the excersise as three separate programs? Complete each and then combine the programs into one at the end.<br>
<br>
Get the book - or the Nutshell book "Practical C" - and make a start. When you hit a problem - get back to us. <br>
<br>
We're more than willing to help but it's easier to help with very specific problems rather than a "How do I write a program that..." sort of question.<br>
<br>
Email me with any specific queries if you'd rather but remember that most people who use discussion groups like this don't actually post anything - they just read everything. So it's more useful to post queries - then everyone can see the answers.<br>
<br>
Regards<br>
<br>
Mike<br>
---<br>
Mike_Lacey@Cargill.Com<br>

 
The reason you probly don't know how to write a command line program is because you only know that main() is just main()... You probly havn't found out that there are arguments passed to it. <br>
<br>
By now, a few days down the road you probly have found this information. But others may have not. So:<br>
<br>
int main (int argc, char* argv[])<br>
<br>
argc is the number of parameters passed<br>
argv is everything that was passed split into an array of strings <br>
<br>
The variable names can be changed to whatever you want, but they have to be those types. I have seen argv be a char** before, but don't remember where from.<br>
<br>
Hope this helps
 
You've to take the command line arguments in argv(). The arguments are separated by a blank space. And the number of argument is stored in argc. The main complexity is in the last argument. Better if you pass it by separating with a space. Or else the last arguments need to be checked for the speacial character like '/'. <br>
<br>
Pseudocode. <br>
<br>
1) Check for the last argument . If it contains '/'. <br>
2) If yes then count the number of '/'. <br>
3) According to the argument , you need to produce that many output files.<br>
<br>
Does it answer your question ?<br>
Thanx<br>
Siddhartha Singh<br>
<A HREF="mailto:ssingh@aztecsoft.com">ssingh@aztecsoft.com</A>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top