From 5b486b03a5c2a444447b13a4c16af667ad3b4935 Mon Sep 17 00:00:00 2001 From: Tejaswini Khandekar <90246533+teekhandekar@users.noreply.github.com> Date: Sun, 14 Nov 2021 22:31:56 +0530 Subject: [PATCH] Create command line argument --- DAY50/command line argument | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 DAY50/command line argument diff --git a/DAY50/command line argument b/DAY50/command line argument new file mode 100644 index 0000000..bf92327 --- /dev/null +++ b/DAY50/command line argument @@ -0,0 +1,33 @@ +#include +#include + +int main(int argc, char* argv[]) +{ + int option = 0; + + while ((option = getopt(argc, argv, ":if:lrx")) != -1) { + switch (option) { + case 'i': + case 'l': + case 'r': + printf("option: %c\n", option); + break; + case 'f': + printf("filename: %s\n", optarg); + break; + case ':': + printf("Option needs a value\n"); + break; + case '?': + printf("unknown option: %c\n", optopt); + break; + } + } + + while (optind < argc) { + printf("Extra arguments: %s\n", argv[optind]); + optind++; + } + + return 0; +}