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
| #include <stdlib.h>
#include <stdio.h>
#include <string.h>
/* Buffer de 5 char, a changer pour un plus grand au cas ou ! */
#define BUFFER_SIZE 5
static int choice_menu (void)
{
char buf [BUFFER_SIZE] = { 0 };
int val = 0;
printf ("Lecture : 1\nEcriture : 2\n");
fflush (stdout);
/* On recupere la saisie utilisateur : */
if ((fgets (buf, BUFFER_SIZE, stdin)) != NULL)
{
/* Suppression du \n s'il y'a. */
{
char * p = NULL;
if (buf != NULL)
{
p = strchr (buf, '\n');
if (p != NULL)
{
*p = 0;
}
}
}
val = strtol (buf, NULL, 10);
}
return val;
}
int main (void)
{
int val = 0;
do
{
val = choice_menu ();
}
while (val != 1 && val != 2);
return EXIT_SUCCESS;
} |
Partager