IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

resultats extravagant lors de calculs


Sujet :

C

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    115
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 115
    Par défaut resultats extravagant lors de calculs
    Hello,
    Voila, j'essaie de créer un petit programme permetant de calculer l'IMC d'une personne, mais voila, lors de l'execution, le programme me renvoie des resultat de type -265120715...
    le programme va lire une structure dans un fichier, et fait le calcul via 2 resultats recupéré.
    je vous met une partit de mon code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    #include <stdio.h>
    #include <stdlib.h>
     
    #define NOM 30
    #define PRENOM 30
    #define DATE_NAISSANCE 10
    #define NIVEAU 30
    #define CONTACT 10
     
    typedef struct 
    {
    	char Nom[NOM];
    	char Prenom[PRENOM];
    	char DateNaissance[DATE_NAISSANCE];
    	double Poids;
    	double Taille;
    	char Niveau[NIVEAU];
    	int Contact[CONTACT];
    } Adherent;
     
     
    int main()
    {
    	return menuChoix();
    }
     
    int menuAdherent()
    {
    	int choix = 0, sortie = 0;
     
    	while (sortie == 0 && choix>1 || choix<8)
    	{
    		/*effacer ecran*/
    		system ("CLS");
    		printf("--- Gestion des Adherents---\n\n");
    		printf("1) Creer nouvel Adherent\n");
    		printf("7) Calcul de L'IMC\n");
    		printf("8) Menu Principal\n\n");
    		printf("Veuillez faire un choix : \n\n");
    		scanf("%ld",&choix);
     
    		switch(choix)
    		{
    			case 1:
    				adherentNew();
    				break;
    			case 7:
    				calculIMC();
    				break;
    			case 8:
    				sortie = 1;
    				break;
    		}
    	}
    }
     
    //Adherent
    int adherentNew()//1) Ajouter un adherent
    {
    	FILE* fichier = NULL;
    	Adherent Adherent;
     
    	/*Effacer ecran*/
    	system("CLS");
     
    	/*Titre*/
    	printf("-----Nouvel Adherent-----\n");
     
    	/*Saisie*/
    	printf("\nNom : ");
    	scanf("%s",&Adherent.Nom);
    	printf("\nPrenom : ");
    	scanf("%s",&Adherent.Prenom);
    	printf("\nDate de Naissance(JJMMAAAA) : ");
    	scanf("%s",&Adherent.DateNaissance);
    		printf("\nPoids (en Kilo) : ");
    	scanf("%d",&Adherent.Poids);
    		printf("\ntaille (en Cm) : ");
    	scanf("%d",&Adherent.Taille);
    		printf("\nNiveau (Debutant, Moyen, Bon, Expert): ");
    	scanf("%s",&Adherent.Niveau);
    		printf("\nTelephone : ");
    	scanf("%d",&Adherent.Contact);
     
     
    	/*Enregistrement*/
    	fichier=fopen("FichierAdherent.txt","a");
    	if (fichier != NULL)
    	{
    		fprintf(fichier,"%s\n", Adherent.Nom);
    		fprintf(fichier,"%s\n", Adherent.Prenom);
    		fprintf(fichier,"%s\n", Adherent.DateNaissance);
    		fprintf(fichier,"%d\n", Adherent.Poids);
    		fprintf(fichier,"%d\n", Adherent.Taille);
    		fprintf(fichier,"%s\n", Adherent.Niveau);
    		fprintf(fichier,"%d\n\n", Adherent.Contact);
     
    		fclose(fichier);
    		printf("\nEnregistrement effectue avec succes\n");
    	}
    	else
    	{
    		printf("\nImpossible d'ouvrir le fichier\n");
    		getchar();
    	}
     
    	system("PAUSE");
     
    }
     
     
    int calculIMC()
    {
    	FILE* fichier = NULL;
    	Adherent Adherent;
    	int retour = 1;
    	double indice =0;
    	double NewTaille, NewPoids;
    	/*Effacer ecran*/
    	system("CLS");
     
    	/*Recuperation des données*/
    	fichier = fopen("FichierAdherent.txt", "r");		        
     
    		if (fichier != NULL)			
    		{	
    			//faire une boucle qui lit le fichier source 
    			//et ecrit dans la cible la fiche avec eventuellement 
    			//les modifications (qui n'ecrit pas si la fiche est supprime)
    			retour = fscanf(fichier, "%s\n%s\n%s\n%d\n%d\n%s\n%d\n\n",
    					&Adherent.Nom, &Adherent.Prenom, &Adherent.DateNaissance, &Adherent.Poids, &Adherent.Taille, &Adherent.Niveau, &Adherent.Contact);
    			while (retour != EOF)				
    			{			    
    				NewPoids=Adherent.Poids;
    				NewTaille=Adherent.Taille;
     
    				indice = NewPoids / (NewTaille*NewTaille*0.001);
    					printf("%d\n", indice);
     
    				retour = fscanf(fichier, "%s\n%s\n%s\n%d\n%d\n%s\n%d\n\n",
    					&Adherent.Nom, &Adherent.Prenom, &Adherent.DateNaissance, &Adherent.Poids, &Adherent.Taille, &Adherent.Niveau, &Adherent.Contact);
     
    			} 
     
    			//fermer les fichiers
    			fclose(fichier);				
    		}        
     
    	else        
    	{           
    		printf("\nImpossible d'ouvrir le fichier");            
    		getchar();            
    	}
     
     
    	system("PAUSE");
     
    }
    Si quelqu'un aurait une solution/conceil qu'il n'hesite pas
    merci

  2. #2
    Membre éclairé Avatar de emprex
    Homme Profil pro
    auto-entrepreneur
    Inscrit en
    Octobre 2007
    Messages
    219
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : auto-entrepreneur
    Secteur : Services à domicile

    Informations forums :
    Inscription : Octobre 2007
    Messages : 219
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    --------------------Configuration: test - Win32 Debug--------------------
    Compiling...
    test.c
    c:\documents and settings\guillaume\mes documents\dut\test.c(24) : warning C4013: 'menuChoix' undefined; assuming extern returning int
    c:\documents and settings\guillaume\mes documents\dut\test.c(45) : warning C4013: 'adherentNew' undefined; assuming extern returning int
    c:\documents and settings\guillaume\mes documents\dut\test.c(48) : warning C4013: 'calculIMC' undefined; assuming extern returning int
    c:\documents and settings\guillaume\mes documents\dut\test.c(55) : warning C4716: 'menuAdherent' : must return a value
    c:\documents and settings\guillaume\mes documents\dut\test.c(109) : warning C4716: 'adherentNew' : must return a value
    c:\documents and settings\guillaume\mes documents\dut\test.c(158) : warning C4716: 'calculIMC' : must return a value
     
    test.obj - 0 error(s), 6 warning(s)

  3. #3
    Membre chevronné
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    309
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 309
    Par défaut
    le problème provient de tes formats.
    Pour commencer, lorsque tu veux récupérer une chaîne de caractères en utilisant l'identifiant %s, tu dois passer une adresse, il est donc inutile d'utiliser l'opérateur & devant les variables de type char* ou char[], par exemple ici :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    scanf("%s",&Adherent.Nom);
    Il faut écrire :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    scanf("%s", Adherent.Nom);
    Sinon, tes variables Poids et Taille sont de type double, or tu utilises l'identifiant de format %d qui est pour les entiers relatifs sous forme décimal :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    %u = unsigned int (decimal)
    %d = signed int (decimal)
    %o = int (octal)
    %x = int (hexadecimal)
    Pour les nombres à virgule il faut utiliser %f pour les floats, %lf pour les double, %Lf pour les long double.

  4. #4
    Expert éminent
    Avatar de Emmanuel Delahaye
    Profil pro
    Retraité
    Inscrit en
    Décembre 2003
    Messages
    14 512
    Détails du profil
    Informations personnelles :
    Âge : 69
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2003
    Messages : 14 512
    Par défaut
    Citation Envoyé par theoffss Voir le message
    Si quelqu'un aurait une solution/conceil qu'il n'hesite pas
    La solution est simple. Il faut corriger les erreurs de ton code. Pour les détecter, un compilateur bien réglé peut aider :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    Project   : Forums
    Compiler  : GNU GCC Compiler (called directly)
    Directory : C:\dev\forums\
    --------------------------------------------------------------------------------
    Switching to target: default
    Compiling: main.c
    main.c:23: warning: function declaration isn't a prototype
    main.c: In function `main':
    main.c:24: warning: implicit declaration of function `menuChoix'
    main.c: At top level:
    main.c:28: warning: function declaration isn't a prototype
    main.c: In function `menuAdherent':
    main.c:31: warning: suggest parentheses around && within ||
    main.c:40: warning: long int format, int arg (arg 2)
    main.c:45: warning: implicit declaration of function `adherentNew'
    main.c:48: warning: implicit declaration of function `calculIMC'
    main.c:55: warning: control reaches end of non-void function
    main.c: At top level:
    main.c:59: warning: function declaration isn't a prototype
    main.c: In function `adherentNew':
    main.c:71: warning: char format, different type arg (arg 2)
    main.c:73: warning: char format, different type arg (arg 2)
    main.c:75: warning: char format, different type arg (arg 2)
    main.c:77: warning: int format, double arg (arg 2)
    main.c:79: warning: int format, double arg (arg 2)
    main.c:81: warning: char format, different type arg (arg 2)
    main.c:83: warning: int format, different type arg (arg 2)
    main.c:93: warning: int format, double arg (arg 3)
    main.c:94: warning: int format, double arg (arg 3)
    main.c:96: warning: int format, pointer arg (arg 3)
    main.c:109: warning: control reaches end of non-void function
    main.c: At top level:
    main.c:113: warning: function declaration isn't a prototype
    main.c: In function `calculIMC':
    main.c:131: warning: char format, different type arg (arg 3)
    main.c:131: warning: char format, different type arg (arg 4)
    main.c:131: warning: char format, different type arg (arg 5)
    main.c:131: warning: int format, double arg (arg 6)
    main.c:131: warning: int format, double arg (arg 7)
    main.c:131: warning: char format, different type arg (arg 8)
    main.c:131: warning: int format, different type arg (arg 9)
    main.c:138: warning: int format, double arg (arg 2)
    main.c:141: warning: char format, different type arg (arg 3)
    main.c:141: warning: char format, different type arg (arg 4)
    main.c:141: warning: char format, different type arg (arg 5)
    main.c:141: warning: int format, double arg (arg 6)
    main.c:141: warning: int format, double arg (arg 7)
    main.c:141: warning: char format, different type arg (arg 8)
    main.c:141: warning: int format, different type arg (arg 9)
    main.c:158: warning: control reaches end of non-void function
    Linking console executable: console.exe
    .objs\dev\forums\main.o(.text+0x19): In function `main':
    C:/dev/forums/main.c:24: undefined reference to `menuChoix'
    collect2: ld returned 1 exit status
    Process terminated with status 1 (0 minutes, 2 seconds)
    1 errors, 37 warnings
    Au fait, le code est incomplet...

    Ceci compile sans erreurs, mais ça ne signifie pas que le code soit correct. Pose des questions si tu ne comprends pas.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
     
    #include <stdio.h>
    #include <stdlib.h>
     
    #define NOM 30
    #define PRENOM 30
    #define DATE_NAISSANCE 10
    #define NIVEAU 30
    #define CONTACT 10
     
    typedef struct
    {
       char Nom[NOM];
       char Prenom[PRENOM];
       char DateNaissance[DATE_NAISSANCE];
       double Poids;
       double Taille;
       char Niveau[NIVEAU];
       char Contact[CONTACT];
    }
    Adherent;
     
    //Adherent
    void adherentNew (void)         //1) Ajouter un adherent
    {
       FILE *fichier = NULL;
       Adherent Adherent;
     
       /*Effacer ecran */
       system ("CLS");
     
       /*Titre */
       printf ("-----Nouvel Adherent-----\n");
     
       /*Saisie */
       printf ("\nNom : ");
       scanf ("%s", Adherent.Nom);
       printf ("\nPrenom : ");
       scanf ("%s", Adherent.Prenom);
       printf ("\nDate de Naissance(JJMMAAAA) : ");
       scanf ("%s", Adherent.DateNaissance);
       printf ("\nPoids (en Kilo) : ");
       scanf ("%lf", &Adherent.Poids);
       printf ("\ntaille (en Cm) : ");
       scanf ("%lf", &Adherent.Taille);
       printf ("\nNiveau (Debutant, Moyen, Bon, Expert): ");
       scanf ("%s", Adherent.Niveau);
       printf ("\nTelephone : ");
       scanf ("%s", Adherent.Contact);
     
       /*Enregistrement */
       fichier = fopen ("FichierAdherent.txt", "a");
       if (fichier != NULL)
       {
          fprintf (fichier, "%s\n", Adherent.Nom);
          fprintf (fichier, "%s\n", Adherent.Prenom);
          fprintf (fichier, "%s\n", Adherent.DateNaissance);
          fprintf (fichier, "%f\n", Adherent.Poids);
          fprintf (fichier, "%f\n", Adherent.Taille);
          fprintf (fichier, "%s\n", Adherent.Niveau);
          fprintf (fichier, "%s\n\n", Adherent.Contact);
     
          fclose (fichier);
          printf ("\nEnregistrement effectue avec succes\n");
       }
       else
       {
          printf ("\nImpossible d'ouvrir le fichier\n");
          getchar ();
       }
     
       system ("PAUSE");
     
    }
     
    void calculIMC (void)
    {
       FILE *fichier = NULL;
       Adherent Adherent;
       int retour = 1;
       double indice = 0;
       double NewTaille, NewPoids;
       /*Effacer ecran */
       system ("CLS");
     
       /*Recuperation des données */
       fichier = fopen ("FichierAdherent.txt", "r");
     
       if (fichier != NULL)
       {
          //faire une boucle qui lit le fichier source
          //et ecrit dans la cible la fiche avec eventuellement
          //les modifications (qui n'ecrit pas si la fiche est supprime)
          retour = fscanf (fichier, "%s\n%s\n%s\n%lf\n%lf\n%s\n%s\n\n",
                           Adherent.Nom, Adherent.Prenom,
                           Adherent.DateNaissance, &Adherent.Poids,
                           &Adherent.Taille, Adherent.Niveau, Adherent.Contact);
          while (retour != EOF)
          {
             NewPoids = Adherent.Poids;
             NewTaille = Adherent.Taille;
     
             indice = NewPoids / (NewTaille * NewTaille * 0.001);
             printf ("%f\n", indice);
     
             retour = fscanf (fichier, "%s\n%s\n%s\n%lf\n%lf\n%s\n%s\n\n",
                              Adherent.Nom, Adherent.Prenom,
                              Adherent.DateNaissance, &Adherent.Poids,
                              &Adherent.Taille, Adherent.Niveau,
                              Adherent.Contact);
     
          }
     
          //fermer les fichiers
          fclose (fichier);
       }
     
       else
       {
          printf ("\nImpossible d'ouvrir le fichier");
          getchar ();
       }
     
       system ("PAUSE");
     
    }
     
    void menuAdherent (void)
    {
       int choix = 0, sortie = 0;
     
       while (sortie == 0 && (choix > 1 || choix < 8))
       {
          /*effacer ecran */
          system ("CLS");
          printf ("--- Gestion des Adherents---\n\n");
          printf ("1) Creer nouvel Adherent\n");
          printf ("7) Calcul de L'IMC\n");
          printf ("8) Menu Principal\n\n");
          printf ("Veuillez faire un choix : \n\n");
          scanf ("%d", &choix);
     
          switch (choix)
          {
          case 1:
             adherentNew ();
             break;
          case 7:
             calculIMC ();
             break;
          case 8:
             sortie = 1;
             break;
          }
       }
    }
     
    int main (void)
    {
       menuAdherent ();
       return 0;
    }

  5. #5
    Membre éclairé Avatar de emprex
    Homme Profil pro
    auto-entrepreneur
    Inscrit en
    Octobre 2007
    Messages
    219
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : auto-entrepreneur
    Secteur : Services à domicile

    Informations forums :
    Inscription : Octobre 2007
    Messages : 219
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    switch (choix)
          {
          case 1:
             adherentNew ();
             break;
          case 7:
             calculIMC ();
             break;
          case 8:
             sortie = 1;
             break;
          }
    Simplement dans cette portion de code ne faut-il pas ajouter une option default: ?
    du type
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    default :
    puts("choix inconnu...");

  6. #6
    Expert confirmé

    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    10 610
    Détails du profil
    Informations personnelles :
    Âge : 68
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 10 610
    Billets dans le blog
    2
    Par défaut
    si tu veux...

  7. #7
    Membre éclairé Avatar de emprex
    Homme Profil pro
    auto-entrepreneur
    Inscrit en
    Octobre 2007
    Messages
    219
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : auto-entrepreneur
    Secteur : Services à domicile

    Informations forums :
    Inscription : Octobre 2007
    Messages : 219
    Par défaut
    En effet je viens de lire que ca n'est qu'une précaution à prendre si l'on veut ajouter un autre cas et il semble qu'il faudrait de plus ajouter break.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    default :
    puts("choix inconnu...");
    break;

  8. #8
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    115
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 115
    Par défaut
    Merci pour el temps que vous m'accordez,

    ensuite, j'ai donc rectifier le code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    #include <stdio.h>
    #include <stdlib.h>
     
    #define NOM 30
    #define PRENOM 30
    #define DATE_NAISSANCE 10
    #define NIVEAU 30
    #define CONTACT 11
     
    typedef struct 
    {
    	char Nom[NOM];
    	char Prenom[PRENOM];
    	char DateNaissance[DATE_NAISSANCE];
    	double Poids;
    	double Taille;
    	char Niveau[NIVEAU];
    	char Contact[CONTACT];
    } Adherent;
    typedef struct 
    {
    	double Date;
    	double Heure;
    	char NomAdherent[NOM];
    } RDV;
     
     
    int main()
    {
    	menuChoix();
    	return 0;
    }
     
    int menuChoix()
    {
    	int sortie = 0;
    	int choix = 0;
     
    	while (sortie == 0 && choix>1 || choix<3)
    	{
    		/*effacer l'ecran*/
    		system("CLS");
     
    		printf("--- Menu Principal ---\n\n");
    		printf("1) Gestion des Adherents\n");
    		printf("2) Gestion des Cours\n");
    		printf("3) Quitter\n\n");
    		printf("Veuillez faire un choix : \n\n");
    		scanf("%ld",&choix);
     
    		switch(choix)
    		{
    			case 1:
    				menuAdherent();	
    				break;
     
    			case 2:
    				menuRDV();
    				break;
     
    			case 3:
    				sortie = 1;
    			break;
    		}
    	}
     
    	return 0;
    }
     
     
    //Menu
    int menuAdherent()
    {
    	int choix = 0, sortie = 0;
     
    	while (sortie == 0 && choix>1 || choix<8)
    	{
    		/*effacer ecran*/
    		system ("CLS");
    		printf("--- Gestion des Adherents---\n\n");
    		printf("1) Creer nouvel Adherent\n");
    		printf("2) Modifier coordonnees adherent\n");
    		printf("3) Supprimer adherent\n");
    		printf("4) Informations adherent\n");
    		//printf("5) Afficher RDV adherent\n");
    		printf("6) Liste des adherents\n");
    		printf("7) Calcul de L'IMC\n");
    		printf("8) Menu Principal\n\n");
    		printf("Veuillez faire un choix : \n\n");
    		scanf("%ld",&choix);
     
    		switch(choix)
    		{
    			case 1:
    				adherentNew();
    				break;
    			case 2:
    				adherentModif();
    				break;
    			case 3:
    				adherentSupp();
    				break;
    			case 4:
    				adherentInfos();
    				break;
    			case 5:
    				/*adherentRDV();*/
    				break;
    			case 6:
    				adherentListe();
    				break;
    			case 7:
    				calculIMC();
    				break;
    			case 8:
    				sortie = 1;
    				break;
    		}
    	}
    }
     
    int menuRDV()
    {
    	int choix = 0, sortie = 0;
     
    	while (sortie == 0 && choix>1 || choix<7)
    	{
    		/*effacer ecran*/
    		system ("CLS");
    		printf("--- Gestion des RDV---\n\n");
    		printf("1) Saisir nouveau rdv\n");
    		printf("2) Modifier date/horaire rdv\n");
    		printf("3) Annuler rdv\n");
    		//printf("4) Affciher les rdv d'aujourd'hui\n");
    		//printf("5) Afficher les rdv d'une date\n");
    		printf("6) Liste des rdv\n");
    		printf("7) Menu Principal\n\n");
    		printf("Veuillez faire un choix : \n\n");
    		scanf("%ld",&choix);
     
    		switch(choix)
    		{
    			case 1:
    				RDVNew();
    				break;
    			case 2:
    				RDVModif();
    				break;
    			case 3:
    				RDVSupp();
    				break;
    			case 4:
    				/*RDVJour();*/
    				break;
    			case 5:
    				/*RDVDate();*/
    				break;
    			case 6:
    				RDVListe();
    				break;
    			case 7:
    				sortie = 1;
    				break;
    		}
    	}
    }
     
     
    //Adherent
    int adherentNew()//1) Ajouter un adherent
    {
    	FILE* fichier = NULL;
    	Adherent Adherent;
     
    	/*Effacer ecran*/
    	system("CLS");
     
    	/*Titre*/
    	printf("-----Nouvel Adherent-----\n");
     
    	/*Saisie*/
    	printf("\nNom : ");
    	scanf("%s",Adherent.Nom);
    	printf("\nPrenom : ");
    	scanf("%s",Adherent.Prenom);
    	printf("\nDate de Naissance(JJMMAAAA) : ");
    	scanf("%s",Adherent.DateNaissance);
    		printf("\nPoids (en Kilo) : ");
    	scanf("%lf",&Adherent.Poids);
    		printf("\ntaille (en Cm) : ");
    	scanf("%lf",&Adherent.Taille);
    		printf("\nNiveau (Debutant, Moyen, Bon, Expert): ");
    	scanf("%s",Adherent.Niveau);
    		printf("\nTelephone : ");
    	scanf("%s",Adherent.Contact);
     
     
    	/*Enregistrement*/
    	fichier=fopen("FichierAdherent.txt","a");
    	if (fichier != NULL)
    	{
    		fprintf(fichier,"%s\n", Adherent.Nom);
    		fprintf(fichier,"%s\n", Adherent.Prenom);
    		fprintf(fichier,"%s\n", Adherent.DateNaissance);
    		fprintf(fichier,"%f\n", Adherent.Poids);
    		fprintf(fichier,"%f\n", Adherent.Taille);
    		fprintf(fichier,"%s\n", Adherent.Niveau);
    		fprintf(fichier,"%s\n\n", Adherent.Contact);
     
    		fclose(fichier);
    		printf("\nEnregistrement effectue avec succes\n");
    	}
    	else
    	{
    		printf("\nImpossible d'ouvrir le fichier\n");
    		getchar();
    	}
     
    	system("PAUSE");
     
    }
     
    int adherentModif()// 2) Modification adherent
    {
    	/* Var*/        
    	FILE* fichier = NULL;		
    	FILE* fichierTemp = NULL;        
    	Adherent Adherent;        
    	char nom[NOM], prenom[PRENOM];        
    	char NewNom[NOM], NewPrenom[PRENOM];        
    	char NewDateNaissance[DATE_NAISSANCE];  
    	double NewPoids, NewTaille;
    	char NewNiveau[NIVEAU];
    	char NewContact[CONTACT];
    	int retour = 1;
    	int trouve = 0;  
     
    	/* Effacer ecran*/        
    	system("CLS");              
    	printf("--- Modification Adherent ---\n");               
     
    	/* Saisie */        
    	printf("\nNom : \n");        
    	scanf("%s", &nom);        
    	printf("\nPrenom : \n");        
    	scanf("%s", &prenom);  
     
    	/* Recuperation + Affichage */		
    	fichier = fopen("FichierAdherent.txt", "r");		        
    	if (fichier != NULL)        
    	{
    		//lire le fichier source en lecture
    		//creer un fichier cible avec un nouveau nom
    		fichierTemp = fopen("FichierAdherentTemp.txt", "w+");
    		if (fichierTemp != NULL)			
    		{	
    			//faire une boucle qui lit le fichier source 
    			//et ecrit dans la cible la fiche avec eventuellement 
    			//les modifications (qui n'ecrit pas si la fiche est supprime)
    			retour = fscanf(fichier, "%s\n%s\n%s\n%lf\n%lf\n%s\n%d\n\n",
    					Adherent.Nom, Adherent.Prenom, Adherent.DateNaissance, &Adherent.Poids, &Adherent.Taille, Adherent.Niveau, Adherent.Contact);
    			while (retour != EOF)				
    			{			    
    				if (strcmp(Adherent.Nom, nom) == 0 && strcmp(Adherent.Prenom, prenom) == 0)
    				{
    					printf("\nNouveau nom : ");
    					scanf("%s", NewNom);
    					printf("\nNouveau prenom : ");
    					scanf("%s", NewPrenom);
    					printf("\nNouvel date de naissance : \n");
    					scanf("%s", NewDateNaissance);
    					printf("\nNouveau poids : \n");
    					scanf("%lf", &NewPoids);
    					printf("\nNouvel taille : \n");
    					scanf("%lf", &NewTaille);
    					printf("\nNouveau niveau : \n");
    					scanf("%s", NewNiveau);
    					printf("\nNouveau numero : \n");
    					scanf("%s", NewContact);
     
     
    					fprintf(fichierTemp,"%s\n", NewNom);
    					fprintf(fichierTemp,"%s\n", NewPrenom);
    					fprintf(fichierTemp,"%s\n\n", NewDateNaissance);
    					fprintf(fichierTemp,"%f\n", NewPoids);
    					fprintf(fichierTemp,"%f\n", NewTaille);
    					fprintf(fichierTemp,"%s\n", NewNiveau);
    					fprintf(fichierTemp,"%s\n", NewContact);
     
    					trouve = 1;
    				}					
    				else					
    				{						
    					fprintf(fichierTemp, "%s\n", Adherent.Nom);	
    					fprintf(fichierTemp, "%s\n", Adherent.Prenom);	
    					fprintf(fichierTemp, "%s\n\n", Adherent.DateNaissance);	
    					fprintf(fichierTemp, "%f\n", Adherent.Poids);	
    					fprintf(fichierTemp, "%f\n", Adherent.Taille);	
    					fprintf(fichierTemp, "%s\n", Adherent.Niveau);	
    					fprintf(fichierTemp, "%s\n", Adherent.Contact);	
     
    				}			   
    				retour = fscanf(fichier, "%s\n%s\n%s\n%lf\n%lf\n%s\n%d\n\n",
    					Adherent.Nom, Adherent.Prenom, Adherent.DateNaissance, &Adherent.Poids, &Adherent.Taille, Adherent.Niveau, Adherent.Contact);
    			} 
     
    			//fermer les fichiers
    			fclose(fichier);	
    			fclose(fichierTemp);	
     
    			if (trouve != 1)			   
    			{			             
    				printf("\nAdherent inconnu\n\n");						 
    				//system("PAUSE");						 
    				//return 0;			   
    			}
    		}        
    	}        
    	else        
    	{           
    		printf("\nImpossible d'ouvrir le fichier");            
    		getchar();            
    	}
     
    	//effacer le fichier source
    	remove("FichierAdherent.txt");	
    	//renomer le fichier cible avec le nom du fichier source
    	rename("FichierAdherentTemp.txt", "FichierAdherent.txt"); 
     
    	system("PAUSE");
     
    }
     
    int adherentSupp()//3) Supprimer adherent
    {
    	/* Var*/        
    	FILE* fichier = NULL;		
    	FILE* fichierTemp = NULL;        
    	Adherent Adherent;        
    	char nom[NOM], prenom[PRENOM];            
    	int retour = 0;        
    	int trouve = 0;  
     
    	/* Effacer ecran*/        
    	system("CLS");              
    	printf("--- Suppression Adherent ---\n");               
     
    	/* Saisie */        
    	printf("\nNom : \n");        
    	scanf("%s", &nom);        
    	printf("\nPrenom : \n");        
    	scanf("%s", &prenom);  
     
    	/* Recuperation + Affichage */		
    	fichier = fopen("FichierAdherent.txt", "r");		        
    	if (fichier != NULL)        
    	{	
    		//lire le fichier source en lecture
    		//creer un fichier cible avec un nouveau nom
    		fichierTemp = fopen("FichierAdherentTemp.txt", "w+");
    		if (fichierTemp != NULL)			
    		{	
    			//faire une boucle qui lit le fichier source 
    			//et ecrit dans la cible la fiche avec eventuellement 
    			//les modifications (qui n'ecrit pas si la fiche est supprime)
     
    			retour = fscanf(fichier, "%s\n%s\n%s\n%lf\n%lf\n%s\n%s\n\n",
    					Adherent.Nom, Adherent.Prenom, Adherent.DateNaissance, &Adherent.Poids, &Adherent.Taille, Adherent.Niveau, Adherent.Contact);
    			while (retour != EOF)			
    			{			    
    				if (strcmp(Adherent.Nom, nom) == 0 && strcmp(Adherent.Prenom, prenom) == 0)
    				{
    					trouve = 1;                     	
    				}					
    				else					
    				{						
    					fprintf(fichierTemp, "%s\n", Adherent.Nom);	
    					fprintf(fichierTemp, "%s\n", Adherent.Prenom);	
    					fprintf(fichierTemp, "%s\n", Adherent.DateNaissance);	
    					fprintf(fichierTemp, "%f\n", Adherent.Poids);	
    					fprintf(fichierTemp, "%f\n", Adherent.Taille);	
    					fprintf(fichierTemp, "%s\n", Adherent.Niveau);	
    					fprintf(fichierTemp, "%s\n\n", Adherent.Contact);		
    				}			   
    				retour = fscanf(fichier, "%s\n%s\n%s\n%lf\n%lf\n%s\n%s\n\n",
    					Adherent.Nom, Adherent.Prenom, Adherent.DateNaissance, &Adherent.Poids, &Adherent.Taille, Adherent.Niveau, Adherent.Contact);
    			}
     
    			//fermer les fichiers
    			fclose(fichier);	
    			fclose(fichierTemp);	
    			if (trouve != 1)			   
    			{			             
    				printf("\nAdherent inconnu\n\n");						 		   
    			}
    		}        
    	}        
    	else        
    	{           
    		printf("Impossible d'ouvrir le fichier");            
    		getchar();            
    	}
    	//effacer le fichier source
    	remove("FichierAdherent.txt");	
    	//renomer le fichier cible avec le nom du fichier source
    	rename("FichierAdherentTemp.txt", "FichierAdherent.txt"); 
     
    	system("PAUSE");
     
    }
     
    int adherentInfos()//4) Informations adherent
    {
    			/* Var*/        
    	FILE* fichier = NULL;		      
    	Adherent Adherent;        
    	char nom[NOM], prenom[PRENOM];               
    	int retour = 0;        
    	int position = 0;
    	int trouve = 0;  
     
    	/* Effacer ecran*/        
    	system("CLS");              
    	printf("--- Informations Adherent ---\n");               
     
    	/* Saisie */        
    	printf("\nNom : \n");        
    	scanf("%s", &nom);        
    	printf("\nPrenom : \n");        
    	scanf("%s", &prenom);  
     
    	/* Recuperation + Affichage */		
    	fichier = fopen("FichierAdherent.txt", "r");		        
    	if (fichier != NULL)  
    			{
    					retour = fscanf(fichier, "%s\n%s\n%s\n%lf\n%lf\n%s\n%s\n\n",
    					Adherent.Nom, Adherent.Prenom, Adherent.DateNaissance, &Adherent.Poids, &Adherent.Taille, Adherent.Niveau, Adherent.Contact);
    			while (retour != EOF)
    				{
    				if (strcmp(Adherent.Nom, nom) == 0 && strcmp(Adherent.Prenom, prenom) == 0)
    				{
    					printf("\n%s\n", Adherent.Nom);
    					printf("%s\n", Adherent.Prenom);
    					printf("%s\n", Adherent.DateNaissance);
    					printf("%.2f\n", Adherent.Poids);
    					printf("%.2f\n", Adherent.Taille);
    					printf("%s\n", Adherent.Niveau);
    					printf("%s\n\n", Adherent.Contact);
     
     
     
    					trouve = 1;
    				}
    			retour = fscanf(fichier, "%s\n%s\n%s\n%lf\n%lf\n%s\n%s\n\n",
    					Adherent.Nom, Adherent.Prenom, Adherent.DateNaissance, &Adherent.Poids, &Adherent.Taille, Adherent.Niveau, Adherent.Contact);
    				}
     
    				fclose(fichier);
    				if (trouve != 1)
    				{
    					printf("\nAdherent inconnu\n\n");	
    				}
    			}
    			else        
    	{           
    			printf("Impossible d'ouvrir le fichier");            
    			getchar();            
    	}
     
    	system("PAUSE");
     
    }
     
    int adherentListe()//6) Lister les adherents
    {
    	FILE* fichier = NULL;
    	Adherent Adherent;
    	int retour = 1;
     
    	/*Effacer ecran*/
    	system("CLS");
     
    	/*Titre*/
    	printf("--- Liste Adherents ---\n");
     
    	/*Recuperation des données*/
    	fichier=fopen("FichierAdherent.txt","r");
     
    	if (fichier != NULL)
    	{
    					retour = fscanf(fichier, "%s\n%s\n%s\n%lf\n%lf\n%s\n%s\n\n",
    					&Adherent.Nom, &Adherent.Prenom, &Adherent.DateNaissance, &Adherent.Poids, &Adherent.Taille, &Adherent.Niveau, &Adherent.Contact);
    		while (retour != EOF)
    		{
    					printf("\n%s\n", Adherent.Nom);
    					printf("%s\n", Adherent.Prenom);
    					printf("%s\n", Adherent.DateNaissance);
    					printf("%.2f\n", Adherent.Poids);
    					printf("%.2f\n", Adherent.Taille);
    					printf("%s\n", Adherent.Niveau);
    					printf("%s\n\n", Adherent.Contact);
     
    					retour = fscanf(fichier, "%s\n%s\n%s\n%lf\n%lf\n%s\n%s\n\n",
    					Adherent.Nom, Adherent.Prenom, Adherent.DateNaissance, &Adherent.Poids, &Adherent.Taille, Adherent.Niveau, Adherent.Contact);
     
    		}
     
    		fclose(fichier);
     
    	}
    	else
    	{
    		printf("\nImpossible d'ouvrir le fichier\n");
    		getchar();
    	}
     
    	system("PAUSE");
     
    }
     
    int calculIMC()
    {
    	FILE* fichier = NULL;
    	Adherent Adherent;
    	int retour = 1;
    	double indice =0;
    	double NewTaille, NewPoids;
    	/*Effacer ecran*/
    	system("CLS");
     
    	/*Recuperation des données*/
    	fichier = fopen("FichierAdherent.txt", "r");		        
     
    		if (fichier != NULL)			
    		{	
    			retour = fscanf(fichier, "%s\n%s\n%s\n%lf\n%lf\n%s\n%s\n\n",
    					Adherent.Nom, Adherent.Prenom, Adherent.DateNaissance, &Adherent.Poids, &Adherent.Taille, Adherent.Niveau, Adherent.Contact);
    			while (retour != EOF)				
    			{			    
    				NewPoids=Adherent.Poids;
    				NewTaille=Adherent.Taille;
     
    				indice = NewPoids / (NewTaille*NewTaille*0.0001);
    					printf("%.2f\n", indice);
     
    				retour = fscanf(fichier, "%s\n%s\n%s\n%lf\n%lf\n%s\n%s\n\n",
    					Adherent.Nom, Adherent.Prenom, Adherent.DateNaissance, &Adherent.Poids, &Adherent.Taille, Adherent.Niveau, Adherent.Contact);
     
    			} 
     
    			//fermer les fichiers
    			fclose(fichier);				
    		}        
     
    	else        
    	{           
    		printf("\nImpossible d'ouvrir le fichier");            
    		getchar();            
    	}
     
     
    	system("PAUSE");
     
    }
    //RDV
    int RDVNew()//1) Nouveau rendez vous
    {
    	FILE* fichier = NULL;
    	RDV RDV;
     
    	/*Effacer ecran*/
    	system("CLS");
     
    	/*Titre*/
    	printf("--- Nouveau RDV ---\n");
     
    	/*Saisie*/
    	printf("\nDate(JJMMAAAA) : ");
    	scanf("%lf",&RDV.Date);
    	printf("\nHeure(HHmm) : ");
    	scanf("%lf",&RDV.Heure);
    	printf("\nNom Adherent : ");
    	scanf("%s",RDV.NomAdherent);
     
    	/*Enregistrement*/
    	fichier=fopen("FichierRDV.txt","a");
    	if (fichier != NULL)
    	{
    		fprintf(fichier,"%f\n", RDV.Date);
    		fprintf(fichier,"%f\n", RDV.Heure);
    		fprintf(fichier,"%s\n\n", RDV.NomAdherent);
    		fclose(fichier);
    		printf("\nEnregistrement effectue avec succes\n");
    	}
    	else
    	{
    		printf("Impossible d'ouvrir le fichier");
    		getchar();
    	}
     
    	system("PAUSE");
    }
     
    int RDVListe()//6) Liste rendez vous
    {
    	FILE* fichier = NULL;
    	RDV RDV;
    	int retour = 0;
     
    	/*Effacer ecran*/
    	system("CLS");
     
    	/*Titre*/
    	printf("--- Liste RDV ---\n");
     
    	/*Recuperation des données*/
    	fichier=fopen("FichierRDV.txt","r");
     
    	if (fichier != NULL)
    	{
    		retour = fscanf(fichier,"%lf\n%lf\n%s\n\n", &RDV.Date,&RDV.Heure,RDV.NomAdherent);
    		while(retour != EOF)
    		{
    			printf("%.2f\n", RDV.Date);
    			printf("%.2f\n", RDV.Heure);
    			printf("%s\n\n", RDV.NomAdherent);
    			retour = fscanf(fichier,"%lf\n%lf\n%s\n\n", &RDV.Date,&RDV.Heure,RDV.NomAdherent);
    		}
     
    		fclose(fichier);
     
    	}
    	else
    	{
    		printf("Impossible d'ouvrir le fichier");
    		getchar();
    	}
     
    	system("PAUSE");
    }
     
    int RDVModif()//2) Modification Rendez vous
    {
    	/* Var*/        
    	FILE* fichier = NULL;		
    	FILE* fichierTemp = NULL;        
    	RDV RDV;        
    	double date,heure;
    	double NewDate, NewHeure; 
    	char NewNomAdherent[NOM];         
    	int retour = 1;        
    	int trouve = 0;  
     
    	/* Effacer ecran*/        
    	system("CLS");              
    	printf("--- Modification RDV ---\n");               
     
    	/* Saisie */        
    	printf("\nDate JJMMAAAA: \n");        
    	scanf("%lf", &date);        
    	printf("\nHeure HHMM: \n");        
    	scanf("%lf", &heure);  
     
    	/* Recuperation + Affichage */		
    	fichier = fopen("FichierRDV.txt", "r");		        
    	if (fichier != NULL)        
    	{
    		//lire le fichier source en lecture
    		//creer un fichier cible avec un nouveau nom
    		fichierTemp = fopen("FichierRDVTemp.txt", "w+");
    		if (fichierTemp != NULL)			
    		{	
    			//faire une boucle qui lit le fichier source 
    			//et ecrit dans la cible la fiche avec eventuellement 
    			//les modifications (qui n'ecrit pas si la fiche est supprime)
     
    			retour = fscanf(fichier,"%lf\n%lf\n%s\n\n", &RDV.Date,&RDV.Heure,RDV.NomAdherent);
    			while (retour != EOF)
    			{				    
    				if (!trouve && RDV.Date == date && RDV.Heure == heure)
    				{
    					printf("\nNouvelle date : ");
    					scanf("%lf", &NewDate);
    					printf("\nNouvelle heure : ");
    					scanf("%lf", &NewHeure);
    					printf("\nAdherent : \n");
    					scanf("%s", &NewNomAdherent);
     
    					fprintf(fichierTemp,"%f\n", NewDate);
    					fprintf(fichierTemp,"%f\n", NewHeure);
    					fprintf(fichierTemp,"%s\n\n", NewNomAdherent);
     
    					trouve = 1;
    				}
    				else					
    				{						
    					fprintf(fichierTemp, "%f\n", RDV.Date);		
    					fprintf(fichierTemp, "%f\n", RDV.Heure);		
    					fprintf(fichierTemp, "%s\n\n", RDV.NomAdherent);	
    				}
     
    				retour = fscanf(fichier,"%lf\n%lf\n%s\n\n", &RDV.Date,&RDV.Heure,RDV.NomAdherent);
    			}
    		}
     
    		//fermer les fichiers
    		fclose(fichier);	
    		fclose(fichierTemp);	
     
    		if (trouve != 1)			   
    		{			             
    			printf("\nRDV inconnu\n\n");						 
    			//system("PAUSE");						 
    			//return 0;			   
    		}
    	}        
    	else        
    	{           
    		printf("\nImpossible d'ouvrir le fichier");            
    		getchar();            
    	}
     
    	//effacer le fichier source
    	remove("FichierRDV.txt");	
    	//renomer le fichier cible avec le nom du fichier source
    	rename("FichierRDVTemp.txt", "FichierRDV.txt"); 
     
    	system("PAUSE");
    }
     
    int RDVSupp()//3) Annuler rendez vous
    {
    	/* Var*/        
    	FILE* fichier = NULL;		
    	FILE* fichierTemp = NULL;        
    	RDV RDV;        
    	double date, heure;
    	int retour = 0;        
    	int trouve = 0;  
     
    	/* Effacer ecran*/        
    	system("CLS");              
    	printf("--- Suppression RDV ---\n");               
     
    	/* Saisie */        
    	printf("\nDate : \n");        
    	scanf("%lf", &date);        
    	printf("\nHeure : \n");        
    	scanf("%lf", &heure);  
     
    	/* Recuperation + Affichage */		
    	fichier = fopen("FichierRDV.txt", "r");		        
    	if (fichier != NULL)        
    	{
    		//lire le fichier source en lecture
    		//creer un fichier cible avec un nouveau nom
    		fichierTemp = fopen("FichierRDVTemp.txt", "w+");
    		if (fichierTemp != NULL)			
    		{	
    			//faire une boucle qui lit le fichier source 
    			//et ecrit dans la cible la fiche avec eventuellement 
    			//les modifications (qui n'ecrit pas si la fiche est supprime)
     
    			retour = fscanf(fichier,"%lf\n%lf\n%s\n\n", &RDV.Date,&RDV.Heure,RDV.NomAdherent);
    			while (retour != EOF)
    			{
    				if ((RDV.Date == date) && (RDV.Heure == heure))
    				{
    					trouve = 1;
    					printf("Rdv supprime /n");
    				}					
    				else					
    				{						
    					fprintf(fichierTemp, "%f\n", RDV.Date);			
    					fprintf(fichierTemp, "%f\n", RDV.Heure);	
    					fprintf(fichierTemp, "%s\n\n", RDV.NomAdherent);	
    				}			   
    				retour = fscanf(fichier,"%lf\n%lf\n%s\n\n", &RDV.Date,&RDV.Heure,&RDV.NomAdherent);
    			}
    		}
     
    		//fermer les fichiers
    		fclose(fichier);	
    		fclose(fichierTemp);	
     
    		if (trouve != 1)	
    		{
    			printf("\nRDV inconnu\n\n");	
    			//system("PAUSE");	
    			//return 0;
    		}
    	}        
    	else        
    	{           
    		printf("Impossible d'ouvrir le fichier");            
    		getchar();            
    	}
     
    	//effacer le fichier source
    	remove("FichierRDV.txt");	
    	//renomer le fichier cible avec le nom du fichier source
    	rename("FichierRDVTemp.txt", "FichierRDV.txt"); 
     
    	system("PAUSE");
    }
    le calcul de l'imc marche parfaitement mais voila plusieurs probleme se créent.

    Mais lorsque je rectifie par l'erreur suivante apparait :"error C2371:'calculIMC':redéfinition, type de base diferent.

    ou encore le warning suivant fscanf a été désaprouvé

    (j'utilise visual studio 2005)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème d'arrondis lors de calculs
    Par stick25 dans le forum Général VBA
    Réponses: 1
    Dernier message: 30/03/2010, 10h36
  2. Problème lors du calcul entre 2 dates
    Par thesmall1985 dans le forum Collection et Stream
    Réponses: 6
    Dernier message: 25/03/2010, 15h06
  3. Réponses: 1
    Dernier message: 11/07/2007, 17h37
  4. Réponses: 3
    Dernier message: 02/07/2007, 18h25
  5. Résultat anormal lors de calcul Double
    Par totore dans le forum Langage
    Réponses: 8
    Dernier message: 04/12/2006, 00h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo