My program will receive a command like
./a.out echo $3 $1 ">" log.txt
i need to replace the $3 with 3 and 1 to use latter when reading from stdin, at this moment i have my code like this (its only doing for one $n at this moment):
int total = argc-1;
int coluna =0;
int i,n,cut,s, pid,status;
char *cmd[total];
char buffer[PIPE_BUF];
char col[10];
char field[10];
//passar argumentos para array
for(i=0;i<total;i++) {
if(i+1 == total) cmd[total+1] = NULL;
else cmd[i] = argv[i+1];
}
//verify for $n
char *tmp = cmd;
for(i=0;i<total-1;i++) {
if(sscanf(tmp,"[$]%s",col) == 1) coluna = atoi(col);
}
the code executes everything else is working (tried without $n, and some other test), but i'm not getting the correct results, seems it ignores the value.
can someone point me my error?