Skip to content

Instantly share code, notes, and snippets.

@caloni
Created August 20, 2020 01:38
Show Gist options
  • Save caloni/1e449591020d636b2cc41fb53245d783 to your computer and use it in GitHub Desktop.
Save caloni/1e449591020d636b2cc41fb53245d783 to your computer and use it in GitHub Desktop.
/** 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