Created
August 20, 2020 01:38
-
-
Save caloni/1e449591020d636b2cc41fb53245d783 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Interpreta argumentos da linha de comando com suporte a arrays. | |
@author Wanderley Caloni <wanderley.caloni@intelitrader.com.br> | |
@date 2020-08 | |
*/ | |
#include <stdlib.h> | |
#include <string.h> | |
const char** GetArgArray(char* argv[], const char* arg) | |
{ | |
char** ret = NULL; | |
size_t cur_off = 0; | |
while (*++argv) | |
{ | |
if (strcmp(*argv, arg) == 0) | |
{ | |
if (*(argv + 1)) | |
{ | |
char* new_arg = *(argv + 1); | |
ret = (char**)realloc(ret, (cur_off + 2) * sizeof(char*)); | |
ret[cur_off++] = new_arg; | |
ret[cur_off] = NULL; | |
} | |
} | |
} | |
return (const char**)ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment