Ir para conteúdo
Fórum Script Brasil

gmaranha

Membros
  • Total de itens

    3
  • Registro em

  • Última visita

Tudo que gmaranha postou

  1. preciso de um vetor de string que será passado como argumento na função execvp.
  2. Estou fazendo um trabalho que preciso da estrutura do tíltulo. #include <stdio.h> #include <stdbool.h> #include <stdlib.h> #include <ctype.h> #include <sys/wait.h> #include <string.h> typedef int token_t; enum{ T_EOL = '\n', T_INPUT = '<', T_OUTPUT = '>', T_PIPE = '|', T_ARGUMENT = 0xFF01 }; #define MAX_ARG_SIZE 10//4096 static bool isargchar(int ch); token_t gettoken(void); void match(token_t token); //essa lista está me confundindo struct arg_t{ char *arg[2];; struct arg_t *next; }; struct arg_t *arg; token_t lookahead; char lexeme[MAX_ARG_SIZE]; int main(int argc, char **argv){ struct arg_t *aux = NULL; int i = 0; /*indice do argumento*/ aux = (struct arg_t*)malloc(sizeof(struct arg_t)); do{ token_t t = gettoken(); char *str; aux->arg[i] = (char *) malloc (sizeof (char) * (strlen ("tst") + 1)); aux->arg[i] = lexeme; i ++; if (i==2){ aux->arg[i] = (char *) malloc (sizeof (char) * (strlen ("tst") + 1)); aux->arg[i] = 0; } } while (i < 2); int j; for (j = 0; j< i; j++){ printf ("arg%d: %s\n", j,aux->arg[j]); } execvp(aux->arg[0], aux->arg); } static bool isargchar(int ch) { return ch != EOF && !isspace(ch) && ch != '>' && ch != '<' && ch != '|'; } token_t gettoken(void) { while(true){ int ch = fgetc(stdin); if(ch == EOF) return EOF; else if(ch == '\n') return T_EOL; else if(isspace(ch)) continue; else if(ch == '>') return T_OUTPUT; else if(ch == '<') return T_INPUT; else if(ch == '|') return T_PIPE; else{ int i = 0; do{ lexeme[i++] = ch; }while(ch = fgetc(stdin),isargchar(ch)); lexeme[i] = 0; ungetc(ch, stdin); return T_ARGUMENT; } } } executando, digito ls -l por exemplo e o vetor da lista fica apenas com -l em todas as posições: ls -l arg0: -l arg1: -l Alguém sabe me dizer o que está acontecendo e como eu posso corrigir?
×
×
  • Criar Novo...