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
| #include <stdio.h>
#include <string.h>
typedef char CH20[21];
typedef char CH10[11];
typedef char CH5[6];
typedef struct
{
CH20 nom;
CH20 prenom;
CH10 tel;
CH5 codeCat;
}
contact;
void inscription (contact[], int[], int *, int *);
void SUPPRESSION (contact[], int[], int, int);
int main (int argc, char **argv)
{
char code;
contact Tab[100];
int j = 0;
int pro = 0;
int TI[100];
/* int TI2[100];
CH20 nomLu, prenomLu;
CH10 telLu;
CH5 codeCatLu; */
printf ("\t\tGestion du repertoire telephonique\n\n"
"Veuillez entrer :\n"
"\tI pour inscrire une personne\n"
"\tS pour supprimer une personne\n"
"\tM pour modifier une personne\n"
"\tT pour afficher tout le repertoire\n\t"
"A pour afficher les relations personnelles\n"
"\tP pour afficher les relations professionnelles\n"
"\tR pour rechercher le telephone d'une personne\n\t"
"N pour rechercher les telephones d'un certain nom\n"
"\tB pour rechercher une personne dont on connait le telephone\n"
"\tQ pour quitter"
"\nRentrez le code : ");
code = getchar ();
scanf ("%*[^\n]"), getchar ();
while (code != 'Q')
{
switch (code)
{
case 'I':
puts ("\n\t\tinscription\n");
inscription (Tab, TI, &j, &pro);
// Verifications
printf ("\nj = %d", j);
printf ("\npro = %d", pro);
printf ("\nTab[0] : %s %s", Tab[0].nom, Tab[0].prenom);
printf ("\n\nRentrez le nouveau code : ");
code = getchar ();
break;
}
}
return 0;
}
void inscription (contact Tab1[], int TI1[], int *cpt, int *cptPro)
{
int i, k = 0, IPDR = 0;
CH20 nomLu, prenomLu;
CH10 telLu;
CH5 codeCatLu;
printf ("Veuillez entrer le nom de la personne a ajouter dans le repertoire.\nNom : ");
scanf ("%20[^\n]", nomLu);
scanf ("%*[^\n]"), getchar ();
printf ("\nVeuillez entrer son prenom.\nPrenom : ");
scanf ("%20[^\n]", prenomLu);
scanf ("%*[^\n]"), getchar ();
for (i = 0; i < *cpt; i++)
{
if ((strcmp (Tab1[i].nom, nomLu) == 0))
{
if ((strcmp (Tab1[i].prenom, prenomLu) == 0))
{
IPDR = i;
k = 1;
i = *cpt - 1;
}
}
}
if (k == 1)
{
printf ("Erreur. Personne deja rentree :\n\n\t");
printf ("%-25s %-25s %-15s %-10s\n\n", Tab1[IPDR].nom, Tab1[IPDR].prenom, Tab1[IPDR].tel, Tab1[IPDR].codeCat);
}
else
{
printf ("\nVeuillez entrer son telephone.\nTelephone : ");
scanf ("%10[^\n]", telLu);
scanf ("%*[^\n]"), getchar ();
printf ("\nVeuillez entrer sa categorie(PRO ou PERSO).\nCategorie : ");
scanf ("%5[^\n]", codeCatLu);
scanf ("%*[^\n]"), getchar ();
if ((strcmp (codeCatLu, "PRO") == 0) || (strcmp (codeCatLu, "PERSO") == 0))
{
strcpy (Tab1[*cpt].nom, nomLu);
strcpy (Tab1[*cpt].prenom, prenomLu);
strcpy (Tab1[*cpt].tel, telLu);
strcpy (Tab1[*cpt].codeCat, codeCatLu);
printf ("\n\nLa personne a bien ete inscrite avec les informations suivantes :");
printf ("\n\n\t%-25s %-25s %-15s %-10s\n\n",
Tab1[*cpt].nom, Tab1[*cpt].prenom,
Tab1[*cpt].tel, Tab1[*cpt].codeCat);
if (strcmp (codeCatLu, "PRO") == 0)
{
TI1[*cptPro] = *cpt;
(*cptPro)++;
}
(*cpt)++;
}
else
{
puts ("\n\nCategorie erronee, inscription non prise en compte.\n");
}
}
getchar ();
} |
Partager