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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char choix[10];
long choix2;
time_t date;
struct tm timet;
char *stringdate;
char buffer[20];
char bufferAnniv[4];
char bufferNom[16];
int nbm;
FILE *fp;
/* Ouverture du fichier en lecture */
fp = fopen ("anniversaire.txt", "r");
printf("DEBUG \n");
if (fp == NULL)
{
perror("Fichier inexistant ! \n");
return EXIT_FAILURE;
}
stringdate = malloc (sizeof(char) * 10);
if (stringdate == NULL)
{
perror("Erreur allocation memoire chaine de caracteres ! \n");
return EXIT_FAILURE;
}
/* Récupération de la date courante et on la formate comme ceci : jjmm */
date = time(NULL);
timet = *gmtime(&date);
strftime (stringdate, 10, "%d%m", &timet);
printf(" --| Nous sommes le %s \n", stringdate);
/* Parcours du fichier */
/* dans bufferAnniv on recopie la date de l'entrée dans le fichier */
/* dans bufferNom on recopie le nom qui correspond a la date */
/* Si la date courante correspond a la date de l'entrée dans le fichier on affiche le nom de la personne */
while( fgets( buffer, sizeof(buffer), fp)!=NULL )
{
nbm = sscanf(buffer, "%s %s", bufferAnniv, bufferNom);
if (nbm != 2)
{
perror("Erreur conversion sscanf \n");
return EXIT_FAILURE;
}
if (strncmp(bufferAnniv, stringdate, 4) == 0)
{
printf(" --| C'est l'anniversaire de %s ! \n", bufferNom);
}
}
printf(" --| 1) Ajouter une entrée \n");
printf(" --| 2) Supprimer une entrée \n");
fgets(choix, sizeof(choix), stdin);
choix2 = strtol(choix, NULL, 10);
printf("Vous avez choisi : %ld \n", choix2);
fclose(fp);
return EXIT_SUCCESS;
} |
Partager