Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
blaar
blibs
blc_program
Commits
552c820c
Commit
552c820c
authored
Jul 31, 2019
by
Arnaud Blanchard
Browse files
Update toshow multiple parameters
parent
4bcb70ba
Changes
2
Hide whitespace changes
Inline
Side-by-side
t_parse_args/CMakeLists.txt
View file @
552c820c
...
...
@@ -17,7 +17,7 @@ project(${PROJECT_NAME})
find_package
(
blc_program
)
#Add your definitions, include directories, sources and libraries now
add_definitions
(
${
BL_DEFINITIONS
}
)
add_definitions
(
${
BL_DEFINITIONS
}
-std=c++14
)
include_directories
(
${
BL_INCLUDE_DIRS
}
)
add_executable
(
${
PROJECT_NAME
}
main.cpp
)
target_link_libraries
(
${
PROJECT_NAME
}
${
BL_LIBRARIES
}
)
t_parse_args/main.cpp
View file @
552c820c
...
...
@@ -4,7 +4,9 @@
int
main
(
int
argc
,
char
**
argv
){
char
const
*
text_option
,
*
first_parameter
,
*
optional_parameter
,
*
flag
;
char
const
*
text_option
,
*
first_parameter
,
*
optional_parameter
;
char
**
parameter_list
;
char
const
*
flag
;
//The text that appear when help is called.
blc_program_set_description
(
"Program to show how to parse arguments."
);
...
...
@@ -18,6 +20,9 @@ int main( int argc, char **argv){
//Accept a second optional argument.
blc_program_add_parameter
(
&
optional_parameter
,
"string"
,
0
,
"Show how to accept simple text as option"
,
NULL
);
//Accept a list of argument of any size ( -1 require at least one, 2 required exactly two).
blc_program_add_multiple_parameters
(
&
parameter_list
,
"string"
,
0
,
"Show how to accept multiple parameters"
);
//Interprets the arguments, associates variables and print program name as title.
blc_program_parse_args
(
&
argc
,
&
argv
);
...
...
@@ -37,7 +42,15 @@ int main( int argc, char **argv){
else
fprintf
(
stderr
,
"- The flag is not activated.
\n
"
);
fprintf
(
stderr
,
"- The first argument is: '%s'
\n
"
,
first_parameter
);
if
(
optional_parameter
)
fprintf
(
stderr
,
"- The optional argument is: '%s'
\n
"
,
optional_parameter
);
if
(
optional_parameter
)
{
fprintf
(
stderr
,
"- The optional argument is: '%s'
\n
"
,
optional_parameter
);
fprintf
(
stderr
,
"- The list of parameters is:
\n
"
);
for
(
char
**
parameter
=
parameter_list
;
*
parameter
!=
nullptr
;
parameter
++
){
fprintf
(
stderr
,
" - %s
\n
"
,
*
parameter
);
}
}
else
fprintf
(
stderr
,
"- No optional argument
\n
"
);
return
0
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment