From 8ee76c2ec08d7e8c096421f34842889423e5586b Mon Sep 17 00:00:00 2001 From: Marco Michele Mosca Date: Thu, 3 Jul 2025 06:59:44 +0100 Subject: [PATCH] Update readme with optarg struct usage --- CHANGELOG | 4 ++++ CMakeLists.txt | 2 +- README.md | 17 +++++++++-------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 11e7d3a..4f51b26 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ All changes to the repository will be reported here +## [0.2.1] +### Updated +- README file with optarg struct usage + ## [0.2.0] ### Changed - Debug build type in CI diff --git a/CMakeLists.txt b/CMakeLists.txt index cfb4217..9e6d1a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ Author Marco M. Mosca, email: marcomichele.mosca@gmail.com ]] cmake_minimum_required(VERSION 3.5.0) -project(cmd-api VERSION 0.2.0 LANGUAGES C) +project(cmd-api VERSION 0.2.1 LANGUAGES C) include(CTest) diff --git a/README.md b/README.md index 606ac0d..5224437 100644 --- a/README.md +++ b/README.md @@ -47,21 +47,22 @@ install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib) ``` #include "cmd-api.h" int main(int argc, char* argv[]) { - char* w; - while ((w = getoptW(argc, argv, "o:|opt1:|opt2:|")) != NULL) + optarg_t* optarg; + while ((optarg = getoptW(argc, argv, "o:|opt1:|opt2:|")) != NULL) { - if (strcmp(w, "o") == 0) { - /*use optargW that has the argument of o*/ + if (strcmp(optarg->opt, "o") == 0) { + /*use optarg->arg that has the argument of o*/ continue; } - if (strcmp(w, "opt1") == 0) { - /*use optargW that has the argument of opt1*/ + if (strcmp(optarg->opt, "opt1") == 0) { + /*use optarg->arg that has the argument of opt1*/ continue; } - if (strcmp(w, "opt2") == 0) { - /*use optargW that has the argument of opt2*/ + if (strcmp(optarg->opt, "opt2") == 0) { + /*use optarg->arg that has the argument of opt2*/ continue; } + free(optarg); } ... }