Commit 552c820c authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Update toshow multiple parameters

parent 4bcb70ba
......@@ -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})
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment