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
replace character into string and return value of string that are replaced

Write a Program to illustrate Array? int x[100]; char text[80]; float temp[30]; static int marks[5]; We are able to use symbolic constants instead of expression. The valu

Prepare a MT4 EA to clone MT4 Trades to a Binary Options Platform Project Description: I want an EA that clones MT4 Trades to Globaltrader365, GT Options and if possible othe

Given an integer n and a permutation of numbers 1, 2 ... , n-1, n write a program to print the permutation that lexicographically precedes the given input permutation. If the given

Unary Minus Operator( Negation) This operand can be used to negate the value of a variable. It is also used to state a negative number, here a minus(-) sign is prefixed to the

write a C program for padovan string for a natural number

Write a program called A1Q3, that reads it the radius of a circle as an integer and prints the circle's diameter, circumference and area.  Use a constant value for pi.  Do all calc



Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve betw   Solution: