IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

problème execv NULL


Sujet :

C

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Novembre 2011
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Novembre 2011
    Messages : 95
    Points : 34
    Points
    34
    Par défaut problème execv NULL
    Bonsoir,

    Je veux exécuter des commandes comme ls mais quand je tape des commandes plus longues que deux caractères, les caractères en plus de passent pas dans ma fonction. J'ai trouvé que c'est cette partie du code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
     void    loop(t_env *env2, char *buffer)
    {
      char  *patate;
      char  **tab1;
      int   i;
     
      i = 0;
      tab1 = init(env2);
      tab1 = my_str_to_wordtab(*my_getenv("PATH", env2->environ), ':');
      i = 0;
      while (tab1[i] != NULL )
        {
          patate = malloc((my_strlen(tab1[i]) + my_strlen(buffer) + 1) * sizeof(char*));
          if (patate == NULL)
            my_putstr_error("errreur amlloc");
          strcat(patate, *tab1);
          del_char(patate, '=');
          del_str(patate, "PATH");
          strcat(patate, "/");
          strcat(patate, buffer);
          i++;
          /* free(patate); */
        }
      /* while (patate[i] != '\0') */
      /*   i++; */
      patate[i] = NULL; /* c'est cette ligne */
      verif(patate);
    }
    Mais quand je l'enlève, execl m'affiche une erreur.

    Merci de votre aide d'avance et bonne soirée.

  2. #2
    Membre émérite
    Avatar de imperio
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2010
    Messages
    852
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2010
    Messages : 852
    Points : 2 298
    Points
    2 298
    Par défaut
    Euh... Je ne comprends pas franchement ce que ton code est suppose faire la... Pourquoi ne pas executer la commande avec ce que te retourne la fonction "my_str_to_wordtab" ?

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Novembre 2011
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Novembre 2011
    Messages : 95
    Points : 34
    Points
    34
    Par défaut
    la fonction my_str_to_wrdtab ne renvoie que le path je le concatène avec la commende à exécuter

  4. #4
    Expert éminent sénior
    Avatar de diogene
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Juin 2005
    Messages
    5 761
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 761
    Points : 13 926
    Points
    13 926
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
          patate = malloc((my_strlen(tab1[i]) + my_strlen(buffer) + 1) * sizeof(char*));
          if (patate == NULL)
            my_putstr_error("errreur amlloc");
          strcat(patate, *tab1);
    - Tu ne peux pas utiliser strcat() pour copier une chaine : elle sert à concaténer deux chaines. La chaine de départ peut évidemment être vide mais ce doit être une chaine donc terminée par '\0'. Ou tu utilises strcpy() ou avant le strcat() tu places le 0 : *patate = '\0'

    - Dans le malloc(), le sizeof(char*) indique que tu veux allouer des pointeurs sur char (auquel cas le type de patate devrait être char**). Tu dois avoir sizeof(char) (ou rien du tout puisqu'il est certain que sizeof(char) ==1)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
      tab1 = init(env2);
      tab1 = my_str_to_wordtab(*my_getenv("PATH", env2->environ), ':');
    Ce code est bizarre : je ne sais pas ce que fait init() ni ce qu'il renvoie, mais dans tous les cas la valeur renvoyée ne sert à rien puisqu'on ne s'en sert pas avant de l'écraser à la ligne suivante.
    Publication : Concepts en C

    Mon avatar : Glenn Gould

    --------------------------------------------------------------------------
    Une réponse vous a été utile ? Remerciez son auteur en cliquant le pouce vert !

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Novembre 2011
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Novembre 2011
    Messages : 95
    Points : 34
    Points
    34
    Par défaut
    init sert a malloc tab1 et d'autres variables. et c'est bien strcat car je veux concaténer patate et tab1.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
     
    char    **init(t_env *env2)
    {
      char  **tab;
     
      env2->s1 = malloc(4096 * sizeof(char*));
      env2->s1 = *my_getenv("PATH", env2->environ);
      env2->s3 = malloc((env2->len) * sizeof(char**));
      tab = malloc((cpt_word(env2->s1, ':') + 1) * sizeof(*tab));
      return (tab);
    }
     
    void    loop(t_env *env2, char *buffer)
    {
      char  *patate;
      char  **tab1;
      int   i;
     
      i = 0;
      tab1 = init(env2);
      tab1 = my_str_to_wordtab(*my_getenv("PATH", env2->environ), ':');
      i = 0;
      while (tab1[i] != NULL )
        {
          patate = malloc((my_strlen(tab1[i]) + my_strlen(buffer) + 1) * sizeof(char*));
          if (patate == NULL)
            my_putstr_error("errreur amlloc");
          patate[0] = '\0';
          strcat(patate, *tab1);
          del_char(patate, '=');
          del_str(patate, "PATH");
          strcat(patate, "/");
          strcat(patate, buffer);
          i++;
          /* free(patate); */
        }
      /* while (patate[i] != '\0') */
      /*   i++; */
      patate[i] = '\0';
      verif(patate);
    }

  6. #6
    Membre émérite
    Avatar de imperio
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2010
    Messages
    852
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2010
    Messages : 852
    Points : 2 298
    Points
    2 298
    Par défaut
    Citation Envoyé par Rémi1995 Voir le message
    la fonction my_str_to_wrdtab ne renvoie que le path je le concatène avec la commende à exécuter
    Pour autant que je sache, ce n'est pas du tout ce que cette fonction est censée faire ! Prenons un exemple :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    char *str = "je/suis/un/test/";
    char **words = my_str_to_wordtab(str, '/');
     
    // contenu de words : ["je", "suis", "un", "test"]
    Donc encore une fois, je ne comprends pas ce que tu veux faire...

  7. #7
    Nouveau membre du Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Novembre 2011
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Novembre 2011
    Messages : 95
    Points : 34
    Points
    34
    Par défaut
    e récupère la path entière ce qui me donne:
    /bin:/sbin:/usr/bin:/usr/sbin:/usr/heimdal/bin:/usr/heimdal/sbin:/home/boivin_r/bin

    ma fonction my_str_to_wordtab me donne

    /bin
    /sbin
    /usr/bin
    /usr/sbin
    /usr/heimdal/bin
    /usr/heimdal/sbin
    /home/boivin_r/bin

    ensuite je la concatène avec buffer et je stockes les deux dans patate.

  8. #8
    Expert éminent sénior
    Avatar de diogene
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Juin 2005
    Messages
    5 761
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 761
    Points : 13 926
    Points
    13 926
    Par défaut
    init sert a malloc tab1 et d'autres variables...
    Je veux bien, mais la ligne qui suit init() détruit l'adresse renvoyée par init().
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
      tab1 = init(env2);
      tab1 = my_str_to_wordtab(*my_getenv("PATH", env2->environ), ':');
    ... c'est bien strcat car je veux concaténer patate et tab1.
    J'ai bien compris, mais le premier appel à strcat() veut être en fait une copie donc il fallait initialiser patate. D'ailleurs, tu l'as rajouté dans le code.

    - Ma remarque sur le sizeof (char*) est toujours valable.
    Publication : Concepts en C

    Mon avatar : Glenn Gould

    --------------------------------------------------------------------------
    Une réponse vous a été utile ? Remerciez son auteur en cliquant le pouce vert !

  9. #9
    Nouveau membre du Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Novembre 2011
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Novembre 2011
    Messages : 95
    Points : 34
    Points
    34
    Par défaut
    donc init ne sert à rien ok merci je vais corriger ça. pour le sizeof char* c'est pour patate ?

  10. #10
    Expert éminent sénior
    Avatar de diogene
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Juin 2005
    Messages
    5 761
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 761
    Points : 13 926
    Points
    13 926
    Par défaut
    init() ne sert pas à rien puisqu'il initialise env2. C'est uniquement un problème d'allocation de tabl : Qui la fait, init() ou my_str_to_wordtab() ? Il faut choisir.

    Pour le sizeof, c'est ici :patate = malloc((my_strlen(tab1[i]) + my_strlen(buffer) + 1) * sizeof(char*)); .
    Publication : Concepts en C

    Mon avatar : Glenn Gould

    --------------------------------------------------------------------------
    Une réponse vous a été utile ? Remerciez son auteur en cliquant le pouce vert !

  11. #11
    Nouveau membre du Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Novembre 2011
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Novembre 2011
    Messages : 95
    Points : 34
    Points
    34
    Par défaut
    j'ai fais comme ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
     
    void    loop(t_env *env2, char *buffer)
    {
      char  *patate;
      char  **tab1;
      int   i;
     
      i = 0;
      tab1 = init(env2);
      i = 0;
      while (tab1[i] != NULL )
        {
          patate = malloc((my_strlen(tab1[i]) + my_strlen(buffer) + 1) * sizeof(char));
          if (patate == NULL)
            my_putstr_error("errreur amlloc");
          patate[0] = '\0';
          strcat(patate, *tab1);
          del_char(patate, '=');
          del_str(patate, "PATH");
          strcat(patate, "/");
          strcat(patate, buffer);
          i++;
          /* free(patate); */
        }
      /* while (patate[i] != '\0') */
      /*   i++; */
      patate[i] = '\0';
      verif(patate);
    }
     
    void    prompt(t_env *env2)
    {
      char  *buffer;
     
      buffer = malloc(4096 * sizeof(char*));
      if (buffer == NULL)
        my_putstr_error("errreur amlloc");
      else
        {
          my_putstr("$-->");
          memset(&buffer[0], 0, 4096);
          if (read(0, buffer, 4095) <= 0)
            {
              my_putstr("[ERROR]");
            }
          else
            {
              loop(env2, buffer);
            }
        }
    }
     
    char    **init(t_env *env2)
    {
      char  **tab;
     
      env2->s1 = malloc(4096 * sizeof(char*));
      env2->s1 = *my_getenv("PATH", env2->environ);
      env2->s3 = malloc((env2->len) * sizeof(char**));
      tab = malloc((cpt_word(env2->s1, ':') + 1) * sizeof(*tab));
      tab = my_str_to_wordtab(*my_getenv("PATH", env2->environ), ':');
      return (tab);
    }

  12. #12
    Expert éminent sénior
    Avatar de diogene
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Juin 2005
    Messages
    5 761
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 761
    Points : 13 926
    Points
    13 926
    Par défaut
    Dans init(), même défaut que tu ne sembles pas comprendre :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
      tab = malloc((cpt_word(env2->s1, ':') + 1) * sizeof(*tab));
      tab = my_str_to_wordtab(*my_getenv("PATH", env2->environ), ':');
    On ne peut avoir ce code : la première ligne fait une allocation et la deuxième détruit aussitôt l'adresse de cette allocation. On ne peut avoir que l'une de ces deux lignes. La question est toujours : Qui fait l'allocation, my_str_to_wordtab() ou pas ?

    Dans loop() :
    A chaque tour de la boucle, tu alloues une nouvelle zone mémoire dont tu mets toujours l'adresse dans une même variable patate. Mais alors, que sont devenues les adresses des zones mémoire allouées précédemment ? Réponse : perdues.
    Publication : Concepts en C

    Mon avatar : Glenn Gould

    --------------------------------------------------------------------------
    Une réponse vous a été utile ? Remerciez son auteur en cliquant le pouce vert !

  13. #13
    Nouveau membre du Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Novembre 2011
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Novembre 2011
    Messages : 95
    Points : 34
    Points
    34
    Par défaut
    my_str_to_wordtab retourne la chaine de caractère avec la path découpé mais elle ne malloc pas tab. J'ai fais comme ça pour la fonction loop
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
     
    void    loop(t_env *env2, char *buffer)
    {
      char  *patate;
      char  **tab1;
      int   i;
     
      i = 0;
      tab1 = init(env2);
      i = 0;
      patate = malloc((my_strlen(tab1[i]) + my_strlen(buffer) + 1) * sizeof(char));
      if (patate == NULL)
        my_putstr_error("errreur amlloc");
      while (tab1[i] != NULL )
        {
          patate[0] = '\0';
          strcat(patate, *tab1);
          del_char(patate, '=');
          del_str(patate, "PATH");
          strcat(patate, "/");
          strcat(patate, buffer);
          i++;
        }
      patate[i] = '\0';
      verif(patate);
    }

  14. #14
    Nouveau membre du Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Novembre 2011
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Novembre 2011
    Messages : 95
    Points : 34
    Points
    34
    Par défaut
    j'ai résolu le problème mais maintenant je n'arrive pas à changer le morceau de path
    par exemple :
    /bin/ls OK // on execute
    /bin/clear error //on continue
    /sbin ...

  15. #15
    Expert éminent sénior
    Avatar de diogene
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Juin 2005
    Messages
    5 761
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 761
    Points : 13 926
    Points
    13 926
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
      i = 0;
      patate = malloc((my_strlen(tab1[i]) + my_strlen(buffer) + 1) * sizeof(char));
    Ceci n'alloue la quantité de mémoire correcte que pour le traitement de tab1[0]

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
          patate[0] = '\0';
          strcat(patate, *tab1);
    Ceci vide la chaine patate au début de chaque tour de la boucle puis remet dans patate toujours la même chose, la chaine pointée par tab1[0]
    Bref, à chaque tour de boucle, on refait la même chose
    Publication : Concepts en C

    Mon avatar : Glenn Gould

    --------------------------------------------------------------------------
    Une réponse vous a été utile ? Remerciez son auteur en cliquant le pouce vert !

  16. #16
    Nouveau membre du Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Novembre 2011
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Novembre 2011
    Messages : 95
    Points : 34
    Points
    34
    Par défaut
    si ce n'ai pas comme ça qu'on fait c'est comment ? pour la path c'est réglé mais comment faire pour qu'ensuite je réaffiche my_putstr("$-->"); ?

  17. #17
    Nouveau membre du Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Novembre 2011
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Novembre 2011
    Messages : 95
    Points : 34
    Points
    34
    Par défaut
    J'ai trouvé pour afficher my_putstr("$-->")
    mais j'ai un petit soucis je voudrai utiliser des commandes avec paramètres comme rm mais quand je fais rm *.o il m'affiche error 2. comment faire pour que je puisse lancer des commandes avec paramètres.

  18. #18
    Membre émérite
    Avatar de imperio
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2010
    Messages
    852
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2010
    Messages : 852
    Points : 2 298
    Points
    2 298
    Par défaut
    Il faut faire appel à une fonction pour transformer ton *.o en tous les fichiers qui matchent cette expression. Fort heureusement, une fonction C le fait.

  19. #19
    Nouveau membre du Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Novembre 2011
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Novembre 2011
    Messages : 95
    Points : 34
    Points
    34
    Par défaut
    OK merci pour la réponse mais maintenant j'ai un autre problème. quand je veux lancer clear il me dit : TERM environment variable not set. j'ai essyer de lancer reset -s xterm mais il m'affiche la même chose. voilà comment j'ai fais

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
     
    int     execute(t_env *env2)
    {
      int   statut;
      int   i;
      pid_t pid;
      char  **argv1;
     
      i = 0;
      env2->arg = my_str_to_wordtab(env2->commande, ' ');
      argv1 = malloc((my_strlen(env2->arg[0]) + 1) * sizeof(char**));
      while (env2->arg[i])
        {
          argv1[i] = malloc((my_strlen(env2->arg[0]) + 1) * sizeof(char**));
          i++;
        }
      if (argv1[0] == NULL)
        my_putstr_error("Error argv1 is NULL\n");
      if ((pid = fork()) == -1)
        my_putstr_error("[ERROR]:fork problem\n");
      if (pid == 0)
        {
          if (execve(env2->arg[0], env2->arg , NULL) == -1)
            {
              return (-1);
              exit(1);
            }
        }
      else
        wait(&statut);
      return 0;
    }
    c'est bon j'avais juste oublier de passer env en paramètre.

  20. #20
    Nouveau membre du Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Novembre 2011
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Lycéen

    Informations forums :
    Inscription : Novembre 2011
    Messages : 95
    Points : 34
    Points
    34
    Par défaut
    je n'arrive pas a passer le chemin a la commande chdir.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
     
    void    prompt(t_env *env2)
    {
      char  *cd;
      char  *cd1;
      char  *tmp;
      int   i;
     
      i = 0;
      env2->buffer = malloc(4096 * sizeof(char*));
      cd = malloc(my_strlen(env2->buffer) * sizeof(char*));
      cd1 = malloc(my_strlen(env2->buffer) * sizeof(char*));
      tmp = malloc(my_strlen(env2->buffer) * sizeof(char*));
      if (cd == NULL || cd1 == NULL || tmp == NULL)
        my_putstr_error("Error malloc");
      if (env2->buffer == NULL)
        my_putstr_error("errreur amlloc");
      else
        {
          my_putstr("$-->");
          memset(&env2->buffer[0], 0, 4096);
          if (read(0, env2->buffer, 4095) <= 0)
              my_putstr("[ERROR]");
          else
            {
              i = 0;
              my_strncpy(cd,env2->buffer,2);
              my_strcpy(cd1, env2->buffer);
              del_str(cd1, cd);
              while (cd1[i] != '\n')
                {
                  tmp[i] = cd1[i];
                  i++;
                }
              if (tmp[i] == '\n')
                printf("ee\n");
              if (strncmp(cd, "cd\n", 2) == 0)
                {
                  printf("%s\n", tmp);
                  if (chdir(tmp) == -1)
                    {
                      perror("error\n");
                      /* exit(1); */
                    }
                  else
                    printf("OK\n");
                }
              else
                loop(env2);
            }
        }
    }

Discussions similaires

  1. [ACCESS-2002][recordset] Problème de NULL
    Par Sephiroth_ttt dans le forum VBA Access
    Réponses: 1
    Dernier message: 30/05/2007, 16h10
  2. problème avec null
    Par HighSchool2005 dans le forum Langage
    Réponses: 6
    Dernier message: 26/04/2007, 11h13
  3. Code : problème avec Null
    Par mat75019 dans le forum Access
    Réponses: 4
    Dernier message: 02/05/2006, 15h01
  4. Lots DTS et import Excel - problème de NULL
    Par gavelin dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 25/01/2006, 15h13
  5. Problème avec NULL
    Par Fiquet dans le forum Débuter
    Réponses: 5
    Dernier message: 26/10/2005, 13h40

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo