Skip to content

Instantly share code, notes, and snippets.

@caloni
Created August 20, 2020 01:41
Show Gist options
  • Save caloni/5b9ccc66722a1b235f4aab8251822cdb to your computer and use it in GitHub Desktop.
Save caloni/5b9ccc66722a1b235f4aab8251822cdb to your computer and use it in GitHub Desktop.
/** Interpreta argumentos da linha de comando (versão raiz).
@author Wanderley Caloni <wanderley.caloni@bitforge.com.br>
@date 2018-08
--- ---
argv: | * |--> | * | "testbin"
--- ---
---
| * | "foo"
---
---
| * | "100"
---
---
argc: | 3 |
---
*/
#include <stdlib.h>
#include <string.h>
const char* GetArg(int argc, char* argv[], const char* arg)
{
for (int i = 1; i < argc; ++i)
{
if( strcmp(argv[i], arg) == 0 )
{
if( i < argc - 1 )
return argv[i+1];
else
return "";
}
}
return NULL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment