Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: C and Cpp Programming in C and Cpp Command Line Arguments Tutorial

How to accept command line arguments (AND checking file existence)

Tutorial Details:

C and Cpp Command Line Arguments

In C++ it is possible to accept command line arguments. Command-line arguments are given after the name of a program in command-line operating systems like DOS or Linux, and are passed in to the program from the operating system. To use command line arguments in your program, you must first understand the full declaration of the main function, which previously has accepted no arguments. In fact, main can actually accept two arguments: one argument is number of command line arguments, and the other argument is a full list of all of the command line arguments.

The integer, argc is the ARGument Count (hence argc). It is the number of arguments passed into the program from the command line, including the name of the program.

The array of character pointers is the listing of all the arguments. argv[0] is the name of the program, or an empty string if the name is not available. After that, every element number less than argc are command line arguments. You can use each argv element just like a string, or use argv as a two dimensional array. argv[argc] is a null pointer.

Almost any program that wants its parameters to be set when it is executed would use this. One common use is to write a function that takes the name of a file and outputs the entire text of it onto the screen.


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
C and Cpp Programming in C and Cpp Command Line Arguments Tutorial

View Tutorial:
C and Cpp Programming in C and Cpp Command Line Arguments Tutorial

Related Tutorials:

Accelerate your Java apps! - JavaWorld - September 1998
Accelerate your Java apps! - JavaWorld - September 1998
 
Java Tip 68: Learn how to implement the Command pattern in Java - JavaWorld - February 1999
Java Tip 68: Learn how to implement the Command pattern in Java - JavaWorld - February 1999
 
Java Tip 70: Create objects from jar files! - JavaWorld - March 1999
Java Tip 70: Create objects from jar files! - JavaWorld - March 1999
 
Java Tip 71: Use dynamic messaging in Java - JavaWorld - April 1999
Java Tip 71: Use dynamic messaging in Java - JavaWorld - April 1999
 
JavaWorld article about JavaCC
JavaWorld article about JavaCC
 
C#: A language alternative or just J--?, Part 2 - JavaWorld December 2000
C#: A language alternative or just J--?, Part 2 - JavaWorld December 2000
 
Build your own languages with JavaCC - JavaWorld December 2000
Build your own languages with JavaCC - JavaWorld December 2000
 
Cut down on logging errors with Jylog
Cut down on logging errors with Jylog
 
Master the Jxta shell, Part 1
Master the Jxta shell, Part 1
 
Integrate Java and C++ with Jace
Integrate Java and C++ with Jace
 
A good article/untrapment about Runtime.exec
A good article/untrapment about Runtime.exec
 
Make a statement with javac!
Make a statement with javac!
 
Using Java Classes in Windows Batch Files
Using Java Classes in Windows Batch Files - a simple approach for system admin Although Java is an ideal language for implementing rich GUI applications, it is equally well-suited for the development of small console-based programs that, in turn, are p
 
Jython
Get to know Jython, in this first article in a new series introducing alternate languages for the Java Runtime Environment, alt.lang.jre. Jython is an implementation of the popular scripting language Python, but running on a JVM. For Python developers Jyt
 
Backing Up and Restoring A MySQL Database
Backing Up and Restoring A MySQL Database Backing Up and Restoring A MySQL Database This tutorial explains the how to backup and restore the MySQL Database. Databases are used to store large amount of precious data and it becomes very important to
 
Java Technology Fundamentals
Learn how to use variable arguments lists, the new JConsole utility to monitor applications, and discover ways to learn what you need to know to get Sun certified.
 
10 Minutes Guide to Ant
10 Minutes Guide to Ant 10 Minutes Guide to Ant Previous Tutorial Index Next Introduction Well for the next 10 minutes get ready to devote to the ant guide. This will make some sence to the ant. Ant is a free tool under GNU Licence and is
 
Building Web Application With Ant and Deploying on Jboss 3.0
Building Web Application With Ant and Deploying on Jboss 3.0 Building Web Application With Ant and Deploying on Jboss 3.0 Previous Tutorial Index Next In this lesson I will show you how to build you web application and install on the Jboss 3.0
 
Using MYSQL Database with JSP & Servlets.
Using MYSQL Database with JSP & Servlets. Using MYSQL Database with JSP & Servlets. MY SQL is a powerful RDBMS, which can handle large amount of data. And more interestingly it is free to use, except for some commercial use. you can download it
 
New Technical Articles: 64-bit Programming on Solaris 10 OS for x86 Platforms
Four technical articles describe the new Sun Studio 10 software's 64-bit programming features on the Solaris 10 OS for x86 and AMD64 platforms. Important issues regarding the AMD64 ABI (Application Binary Interface), debugging, migration to 64-bits, and p
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.