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
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (void)
{
char const *fname = "test.txt";
char *mot = malloc (sizeof *mot * 50);
FILE *f = fopen (fname, "r");
if (mot == NULL)
{
fprintf(stderr, "Malloc failure !\n");
exit(EXIT_FAILURE);
}
if(f == NULL)
{
perror("file()");
exit(EXIT_FAILURE);
}
strcpy (mot, "");
if(fscanf (f, "%s", mot) == 1)
{
if (strcmp (mot, "bonjour") == 0)
{
system ("echo bonjour");
}
}
fclose(f), f = NULL;
free(mot), mot = NULL;
return 0;
} |
Partager