//
//  getchar.c
//  labyrinthe
//
//  Created by léo LELLOUCHE on 12/04/2016.
//  Copyright © 2016 léo LELLOUCHE. All rights reserved.
//

#include "header.h"


void portable_flush()
{
    char c;
    
    c = getchar();
    
    if (c == EOF || c == '\n')
        clearerr(stdin);
    else
        portable_flush();
}

char _getchar()
{
    char c;
    
    c = getchar();
    if (c == '\n')
        return (c);
    portable_flush();
    return (c);
}

char demander_direction(void)
{
    char dir;
    
    dir = _getchar();
    if (dir == '\n')
        return (demander_direction());
    if ((dir != 'z') && (dir != 'q') && (dir != 'd') && (dir != 's'))
    {
        printf("Direction incorrecte\n");
        return(demander_direction());
    }
    return (dir);
}