Command-line arguments, C/C++ Programming

Assignment Help:

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);
}


Related Discussions:- Command-line arguments

Dll, i need amibroker afl to dll plugin

i need amibroker afl to dll plugin

Sparce matrices, Write an algorithm for multiplication of two sparse matric...

Write an algorithm for multiplication of two sparse matrices using Linked Lists.

Super ascii string checker, Program which can check the given string is su...

Program which can check the given string is super ascii or not

Define procedure that take argument or return integral value, Simpson's Rul...

Simpson's Rule is a more accurate method of numerical integration than the method described in class. Using Simpson's Rule, the integral of a function f between a and b is approxim

Program is to define a class as library, Program is to define a class as li...

Program is to define a class as library: Program is to define a class as library and perform all the function of library management by using classes and object class librar

Abcd, #question.gsdjfhjhjfkfk.

#question.gsdjfhjhjfkfk.

Integration, to find the area under the curve y = f(x) between x = a and x ...

to find the area under the curve y = f(x) between x = a and x = b

Electrical eng, calculate the total resisitance of a series circuit?

calculate the total resisitance of a series circuit?

Queue, write a queue program in c langauge?

write a queue program in c langauge?

Explain protected derivation, Protected derivation In addition to doing...

Protected derivation In addition to doing private and public derivations, you may also do a protected derivation. In this situation :   The private members inherited

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd