Sponsored Content
Full Discussion: Input arguments with C++
Top Forums Programming Input arguments with C++ Post 302756697 by Corona688 on Wednesday 16th of January 2013 10:58:13 AM
Old 01-16-2013
This scheme seems a bit messy, since it lets you splatter commandline argument parsing wherever you feel like, instead of keeping it central in main(). And it's not really more organized than the scheme you had before, which was just a big list of variables.

What is a vect2? A 2d vector, but of what, ints, floats, doubles?

Last edited by Corona688; 01-16-2013 at 12:06 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading specific contents from 1 input files and appending it to another input file

Hi guys, I am new to AWK and unix scripting. Please see below my problem and let me know if anyone you can help. I have 2 input files (example given below) Input file 2 is a standard file (it will not change) and we have to get the name (second column after comma) from it and append it... (5 Replies)
Discussion started by: sksahu
5 Replies

2. Shell Programming and Scripting

Accepting user input and arguments in PERL

Hi All, Can we pass arguments while calling the perl script and as well as ask user input during execution of the script? My program is as below: I am passing arg1 and arg2 as argements to test.pl ]./test.pl arg1 arg2 Inside the test.pl I have : print "Do you want a name ? (y/n) : ";... (2 Replies)
Discussion started by: jisha
2 Replies

3. Shell Programming and Scripting

grep with two arguments to arguments to surch for

Hello, is it possible to give grep two documents to surche for? like grep "test" /home/one.txt AND /home/two.txt ? thanks (1 Reply)
Discussion started by: Cybertron
1 Replies

4. Shell Programming and Scripting

Script to delete files with an input for directories and an input for path/file

Hello, I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall: I regularly need to delete files from many directories. A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Discussion started by: *ShadowCat*
3 Replies

5. Shell Programming and Scripting

function terminating if i give input as space or no input and enter

HI i have written a script to ask input from the user. this script should promote the user for y/n input. if user enters anyother input then y/n the script promotes him again. this below code is working fine for all the cases. except for space and enter " if i give space and enter it is... (2 Replies)
Discussion started by: BHASKARREDDY006
2 Replies

6. Shell Programming and Scripting

[Solved] Read and validate input arguments

Hi, I need to get input arguments, as well as validate them. This is how I'm reading them: #!/bin/bash args="$@" # save arguments to variable ## Read input arguments, if so while ; do case $1 in -v | --verbose ) verbose=true;; -z | --gzip ) compression="gz";; ... (3 Replies)
Discussion started by: AlbertGM
3 Replies

7. Shell Programming and Scripting

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies

8. Homework & Coursework Questions

Removing punctuations from file input or standard input

Just started learning Unix and received my first assignment recently. We haven't learned many commands and honestly, I'm stumped. I'd like to receive assistance/guidance/hints. 1. The problem statement, all variables and given/known data: How do I write a shell script that takes in a file or... (4 Replies)
Discussion started by: fozilla
4 Replies

9. Shell Programming and Scripting

How to avoid "Too many arguments" error, when passing a long String literal as input to a command?

Hi, I am using awk here. Inside an awk script, I have a variable which contains a very long XML data in string format (500kb). I want to pass this data (as argument) to curl command using system function. But getting Too many arguments error due to length of string data(payloadBlock). I... (4 Replies)
Discussion started by: cool.aquarian
4 Replies

10. Shell Programming and Scripting

How to pass arguments based on input file?

This script is running some exe file we are passing three argumnet below custome key word Want to update script based on input files every time it will take argument from input file below is the input files should take this input put it into the script. k.ksh cd /u/kali/temp ... (8 Replies)
Discussion started by: Kalia
8 Replies
GETOPT_LONG(3)						   BSD Library Functions Manual 					    GETOPT_LONG(3)

NAME
getopt_long, getopt_long_only -- get long options from command line argument list LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <getopt.h> extern char *optarg; extern int optind; extern int optopt; extern int opterr; extern int optreset; int getopt_long(int argc, char * const *argv, const char *optstring, const struct option *longopts, int *longindex); int getopt_long_only(int argc, char * const *argv, const char *optstring, const struct option *longopts, int *longindex); DESCRIPTION
The getopt_long() function is similar to getopt(3) but it accepts options in two forms: words and characters. The getopt_long() function provides a superset of the functionality of getopt(3). The getopt_long() function can be used in two ways. In the first way, every long option understood by the program has a corresponding short option, and the option structure is only used to translate from long options to short options. When used in this fashion, getopt_long() behaves identically to getopt(3). This is a good way to add long option processing to an existing program with the minimum of rewriting. In the second mechanism, a long option sets a flag in the option structure passed, or will store a pointer to the command line argument in the option structure passed to it for options that take arguments. Additionally, the long option's argument may be specified as a single argument with an equal sign, e.g., myprogram --myoption=somevalue When a long option is processed, the call to getopt_long() will return 0. For this reason, long option processing without shortcuts is not backwards compatible with getopt(3). It is possible to combine these methods, providing for long options processing with short option equivalents for some options. Less fre- quently used options would be processed as long options only. The getopt_long() call requires a structure to be initialized describing the long options. The structure is: struct option { char *name; int has_arg; int *flag; int val; }; The name field should contain the option name without the leading double dash. The has_arg field should be one of: no_argument no argument to the option is expect required_argument an argument to the option is required optional_argument an argument to the option may be presented. If flag is not NULL, then the integer pointed to by it will be set to the value in the val field. If the flag field is NULL, then the val field will be returned. Setting flag to NULL and setting val to the corresponding short option will make this function act just like getopt(3). If the longindex field is not NULL, then the integer pointed to by it will be set to the index of the long option relative to longopts. The last element of the longopts array has to be filled with zeroes. The getopt_long_only() function behaves identically to getopt_long() with the exception that long options may start with '-' in addition to '--'. If an option starting with '-' does not match a long option but does match a single-character option, the single-character option is returned. RETURN VALUES
If the flag field in struct option is NULL, getopt_long() and getopt_long_only() return the value specified in the val field, which is usu- ally just the corresponding short option. If flag is not NULL, these functions return 0 and store val in the location pointed to by flag. These functions return ':' if there was a missing option argument, '?' if the user specified an unknown or ambiguous option, and -1 when the argument list has been exhausted. ENVIRONMENT
POSIXLY_CORRECT If set, option processing stops when the first non-option is found and a leading '-' or '+' in the optstring is ignored. EXAMPLES
int bflag, ch, fd; int daggerset; /* options descriptor */ static struct option longopts[] = { { "buffy", no_argument, NULL, 'b' }, { "fluoride", required_argument, NULL, 'f' }, { "daggerset", no_argument, &daggerset, 1 }, { NULL, 0, NULL, 0 } }; bflag = 0; while ((ch = getopt_long(argc, argv, "bf:", longopts, NULL)) != -1) switch (ch) { case 'b': bflag = 1; break; case 'f': if ((fd = open(optarg, O_RDONLY, 0)) == -1) err(1, "unable to open %s", optarg); break; case 0: if (daggerset) { fprintf(stderr,"Buffy will use her dagger to " "apply fluoride to dracula's teeth "); } break; default: usage(); } argc -= optind; argv += optind; IMPLEMENTATION DIFFERENCES
This section describes differences to the GNU implementation found in glibc-2.1.3: o Setting of optopt for long options with flag != NULL: GNU sets optopt to val. BSD sets optopt to 0 (since val would never be returned). o Setting of optarg for long options without an argument that are invoked via '-W' ('W;' in option string): GNU sets optarg to the option name (the argument of '-W'). BSD sets optarg to NULL (the argument of the long option). o Handling of '-W' with an argument that is not (a prefix to) a known long option ('W;' in option string): GNU returns '-W' with optarg set to the unknown option. BSD treats this as an error (unknown option) and returns '?' with optopt set to 0 and optarg set to NULL (as GNU's man page documents). o BSD does not permute the argument vector at the same points in the calling sequence as GNU does. The aspects normally used by the caller (ordering after -1 is returned, value of optind relative to current positions) are the same, though. (We do fewer variable swaps.) SEE ALSO
getopt(3) HISTORY
The getopt_long() and getopt_long_only() functions first appeared in GNU libiberty. The first BSD implementation of getopt_long() appeared in NetBSD 1.5, the first BSD implementation of getopt_long_only() in OpenBSD 3.3. FreeBSD first included getopt_long() in FreeBSD 5.0, getopt_long_only() in FreeBSD 5.2. BUGS
The argv argument is not really const as its elements may be permuted (unless POSIXLY_CORRECT is set). The implementation can completely replace getopt(3), but right now we are using separate code. BSD
April 1, 2000 BSD
All times are GMT -4. The time now is 01:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy