Modification biblio fonction get_input
La fonction ne modifie plus le paramètre mais retourne un pointeur vers la chaine entrée.
This commit is contained in:
parent
5e72cf5020
commit
f717909921
3 changed files with 7 additions and 38 deletions
|
@ -14,10 +14,11 @@
|
|||
* get_input(): Permet de récupérer la saisie de l’utilisateur
|
||||
* @user_input: string où sera enregistrée l’entrée de l’utilisateur
|
||||
*/
|
||||
void get_input(char *user_input)
|
||||
char* get_input()
|
||||
{
|
||||
char *buffer = (char *) malloc(MAX_LENGTH);
|
||||
memset(user_input, 0, MAX_LENGTH);
|
||||
memset(buffer, 0, MAX_LENGTH);
|
||||
|
||||
printf("\n> ");
|
||||
fgets(buffer, MAX_LENGTH, stdin);
|
||||
while (buffer[0] == '\n')
|
||||
|
@ -25,8 +26,8 @@ void get_input(char *user_input)
|
|||
printf("\n> ");
|
||||
fgets(buffer, MAX_LENGTH, stdin);
|
||||
}
|
||||
strncpy(user_input, buffer, strlen(buffer)-1);
|
||||
free(buffer);
|
||||
buffer[strlen(buffer)-1] = '\0'; /* pour ne pas avoir un retour à la ligne */
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,9 +40,7 @@ void get_input(char *user_input)
|
|||
*/
|
||||
void parse_char(char *args[], char find)
|
||||
{
|
||||
char *user_input = (char *) malloc(MAX_LENGTH);
|
||||
get_input(user_input);
|
||||
|
||||
char *user_input = get_input();
|
||||
char *token = strtok(user_input, &find);
|
||||
|
||||
int i = 0;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#define MAX_LENGTH 200 /* taille maximum des tableaux utilisés */
|
||||
|
||||
void get_input(char *user_input);
|
||||
char* get_input();
|
||||
void parse_char(char *args[], char find);
|
||||
void tok_space(char *args,char *commands[]);
|
||||
|
||||
|
|
30
src/shell1.c
30
src/shell1.c
|
@ -1,30 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
char *user_input = (char *) malloc(MAX_LENGTH);
|
||||
int result, pid;
|
||||
get_input(user_input);
|
||||
while (strcmp(user_input, "exit"))
|
||||
{
|
||||
pid = fork();
|
||||
|
||||
if (!pid)
|
||||
{
|
||||
execlp(user_input, user_input, NULL);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
wait(&result);
|
||||
|
||||
get_input(user_input);
|
||||
}
|
||||
free(user_input);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue