O
Owner
What I'm trying to do with argv is
swapping argv[0] to the end and files argument to the front
reason I'm doing that is in English
cmd options file... is nicely read
do this(cmd) how(option) with file...
but in my language
it's more naturally read
file.... option cmd
so I'm playing around with my codes.
this code below keeps changing argv[0] to file1
can anyone find a fault code below?
Thank you in advance.
void hcmd(int argc, char *argv[])
{
int i, j;
int opcount, agcount;
char **k, **op, **ag;
char *tmp;
char *newarg[100];
k = op = ag = argv;
opcount = agcount = 0;
/* Saving Command */
*k = argv[0];
/* first Option */
if (argc == 1) return;
i = 1;
if (argv[0] == '-' || argv[0] == '/'){
*op = argv[i++];
opcount++;
}
/* counting rest of options */
for (;i < argc && argv[0] == '-' || argv[0] == '/';i++)
opcount++;
/* first argument */
if (i < argc){
*ag = argv[i++];
agcount++;
}
/* rest of argument */
for (; i < argc; i++)
agcount++;
for(i=0; i< argc; i++)
printf("%s ", argv);
}
swapping argv[0] to the end and files argument to the front
reason I'm doing that is in English
cmd options file... is nicely read
do this(cmd) how(option) with file...
but in my language
it's more naturally read
file.... option cmd
so I'm playing around with my codes.
this code below keeps changing argv[0] to file1
can anyone find a fault code below?
Thank you in advance.
void hcmd(int argc, char *argv[])
{
int i, j;
int opcount, agcount;
char **k, **op, **ag;
char *tmp;
char *newarg[100];
k = op = ag = argv;
opcount = agcount = 0;
/* Saving Command */
*k = argv[0];
/* first Option */
if (argc == 1) return;
i = 1;
if (argv[0] == '-' || argv[0] == '/'){
*op = argv[i++];
opcount++;
}
/* counting rest of options */
for (;i < argc && argv[0] == '-' || argv[0] == '/';i++)
opcount++;
/* first argument */
if (i < argc){
*ag = argv[i++];
agcount++;
}
/* rest of argument */
for (; i < argc; i++)
agcount++;
for(i=0; i< argc; i++)
printf("%s ", argv);
}