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

Develop libcurl xml project, Develop libcurl XML project I have a Projec...

Develop libcurl XML project I have a Project using XML with C++. You will use things like LIbcurl etc....and a XML parser to finish the project. Developer must know how to use X

Program for hangman game problem, Program for Hangman Problem   #inclu...

Program for Hangman Problem   #include   #include   #include   #include   #include   static void playGame();   static void printMistakes(int n);   st

Define the logical operators in c language, Define the Logical Operators in...

Define the Logical Operators in c language? The Logical operators deals with the ways the relationships are able to connected. C has the following three logical operators

Area under curve, write a program to find the area under the curve y=f(x) b...

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 #include float start_point,

Type cast operator, What is  T y pe C a s t Op er a t o r :...

What is  T y pe C a s t Op er a t o r :   T h e f l o a t c a n b e c o n v e r t e d t o i n t e g e r v a l u

#include, Write a program to find the area under the curve y = f(x) between...

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 between two points can b

Define external storage class - computer programming, Define External Stora...

Define External Storage Class - computer programming? When a variable is declared outside a function the storage is permanently assigned to it and its storage class is 'extern'

Program is to perform all the functions of super bazaar, Program is to perf...

Program is to perform all the functions that are performed in a super bazaar: class stock   {   private:     int itno;     char itname[20];     char brname[20];

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