Sujet : Re: macro for fir list?
De : fir (at) *nospam* grunge.pl (fir)
Groupes : comp.lang.cDate : 29. Mar 2024, 09:31:16
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <uu5u8p$3dffl$1@i2pn2.org>
References : 1 2 3 4
User-Agent : Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
fir wrote:
>
// sickle.h
struct str_list_entry { char* str;};
const int str_lists_max = 10;
str_list_entry* str_list[str_lists_max] = {NULL};
int str_list_size[str_lists_max] = {0};
str_list_entry* str_list_new(int N) {
str_list[N] = (str_list_entry*) realloc(str_list[N],
++str_list_size[N] * sizeof(str_list_entry) );
return &str_list[N][str_list_size[N]-1]; }
>
you can use the above for example to build list from commanline
const int commandline_list_key = 0;
void BuildListOfComandline(int argc, char* argv[])
{
for(int i=0; i<argc; i++)
*str_list_new(commandline_list_key)={argv[i]};
}
int main(int argc, char* argv[])
{
BuildListOfComandline( argc, argv);
for(int i=0; i<str_list_size[commandline_list_key];i++)
printf("\n%d %s", i, str_list[commandline_list_key][i].str);
}
the names here are maybe to long as for such common use items so some abrreviation should be used