Skip to content

Files

Latest commit

 

History

History
36 lines (30 loc) · 935 Bytes

compact_flags.md

File metadata and controls

36 lines (30 loc) · 935 Bytes

Compact Flags

Compact flags are a type of flag , that its setted in one arg, ass a prefix exemple name:mateus where name: its the flag and mateus its the value

#include "CArgvParseOne.c"
#include <stdio.h>


CArgvParseNamespace argv_namespace;
int main(int argc, char *argv[]){
    argv_namespace = newCArgvParseNamespace();
    CArgvParse args = argv_namespace.newCArgvParse(argc,argv);

    const char *name[] = {"name:","name="};
    int name_size = 2;
    
    int total_names = argv_namespace.get_compact_flag_size(&args,name,name_size);
    printf("total names: %d\n",total_names);
    for(int i = 0; i < total_names; i++){
        const char *name_value = argv_namespace.get_compact_flag(&args,name,name_size,i);
        printf("name: %s\n",name_value);
    }
}

if you run with:

./a.out    name:mateus name=samuel 

your output will be:

total names: 2
name: mateus
name: samuel