Command-line arguments, C/C++ Programming

Command-line arguments are passed into programs using the arguments of main(). Here's a quick example, for a program called by typing

"progname file.txt 1 2.7":
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
char *progname, *filename;
int value1;
float value2;
if (argc != 4) {
cerr << "usage: " << argv[0] << " file.txt int float" << endl;
exit(1);
}
progname = argv[0]; // argv[0] is the executable's name itself
filename = argv[1];
value1 = atoi(argv[2]); // convert C-string to int with atoi()
value2 = atof(argv[3]); // convert C-string to float with atof()
cout << progname << " " << filename << " " << value1 << " " << value2 <exit(0);
}

Posted Date: 3/12/2013 4:10:00 AM | Location : United States







Related Discussions:- Command-line arguments, Assignment Help, Ask Question on Command-line arguments, Get Answer, Expert's Help, Command-line arguments Discussions

Write discussion on Command-line arguments
Your posts are moderated
Related Questions
The Malt Shop restaurant charges $2.99 for burgers, $1.29 for fries, and $1.25 for sodas.  Write a program that allows a restaurant employee to enter an order (the number of bur

Define Internal static storage class - computer programming? The Internal static variables are those that declared inside a function. The scope of the internal static variables

The program must use the file named on the command line as its input file. Suppose the program is named pdbtool. Then if the user types pdbtool 1A36.pdb the program must read the d

Define some features of static storage class in c program? The features of a variable defined to contain a static storage class are as follows. Storage - memory Default

when a class is defined the compiler will not allocate memory. This is true only for data member not for member function.  As soon as the member function is defined  the require

write an algorithm that reads a postive integer n and then finds and prints the sum of all integers between 1 and n (inclusive) that are disvisible by 7. please write this using c

Explain the Symbolic Constants in c language? Symbolic constants are the constants of any type that declared by using the #define compiler directive and it is a preprocessor di

minimum total number of shelves.

please help me get all the inbuilt functions in c++

Q: But operator overloading makes class look ugly; isn't it assumed to make my code clearer? A: Operator overloading makes life simpler for the users of a class, not for develop