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

Datastructure, c program of double linked list with full explanation

c program of double linked list with full explanation

Explain object-oriented programming, Explain Object-oriented programming ...

Explain Object-oriented programming Object-oriented programming (OOP) attempts to meet these requirements, providing methods for managing enormous complexity, achieving reuse o

Demonstration using moss open source machine translation, Demonstration usi...

Demonstration using Moss Open Source Machine Translation Project Description: Moses is an open source Statistical Machine Translation System. I need someone to provide me a d

Assignment, manupulates operator precidence

manupulates operator precidence

Padovanstring, write a program that counts the number of occurances of the ...

write a program that counts the number of occurances of the string in the n-th padovan string p(n)

Z transformer, how to write code for z transformer

how to write code for z transformer

Bubble sort, sample of program that use in bubble sort using assignment ope...

sample of program that use in bubble sort using assignment operator in c++

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