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
#At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with the

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci

Project Description: We are seeking online invoice OCR solution. That will help us to automate accounts payable function. User should be able to use the offered pdf file or s

In this problem you are given a board in which some of the elements are placed as shown in diagram below. Each element represents a color. Fill the other elements in the board, suc

An employee’s total weekly pay equals the hourly wage multiplied by the total number of regular hours plus any overtime pay. Overtime pay equals the total overtime hours multiplied

if one won't explicitly call the destructor of a local; then how does he handle the above situation?

switch statement

The purpose of this assignment is to familiarize you with the notion of encapsulation as well as some aspects of IP and ICMP. Write your programs in C or C++. They will be grade

Define the Classification of Operators in C Language? Depending on the function performed the operator can be classified as 1. Arithmetic Operator 2. Logical Operator 3. Inc

There is a pebble merchant. He sells the pebbles, that are used for shining the floor. His main duty is to take the length of the room’s sides. But he sometimes mistakes doing that