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
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
void clean(const char *buffer, FILE *fp);
//menu
long menu()
{
long choix = 0;
while (choix < 1 || choix > 4)
{
printf("\t\t\tMenu :\n");
printf("1 : consultation\n");
printf("2 : ajout \n");
printf("3 : suppression\n");
printf("4 : quitter\n");
printf("Votre choix ? ");
scanf("%ld", &choix);
}
return choix;
}
int main(int argc, char *argv[])
{
long toto;
//declaration des variables
FILE *fp = NULL;
FILE * f = NULL;
char nom[20+1];
char prenom[20+1];
char messagerie[50+1];
char service[200+1];
char typePlatform[80+1];
char nomExe[80+1];
char nomObject[80+1];
char libelle[80+1];
char sup[80+1];
char dateAno[8+1];
char nomFile[80+1];
char pb[120+1];
toto = menu ();
switch (toto)
{
case 1:
printf("\n\n\tVous avez pris la consultation\n");
break;
case 2:
printf("\n\n\tVous avez pris l'ajout\n");
break;
case 3:
printf("\n\n\tVous avez pris la suppression\n");
break;
printf("\n\n\n");
}
//consultation
if (toto == 1)
{
printf("tapez le nom du fichier a ouvrir : \n");
scanf("%s", &nomFile);
printf("\n\n\n");
fp = fopen (&nomFile, "r");//ouvre le fichier
if (fp != NULL)
{
char ligne[32+1];
int cpt = 0;
while (fgets (ligne, sizeof ligne, fp) != NULL)
{
cpt++;
printf ("%d: %s\n", cpt, ligne);
}
fclose (fp);
}
else
{
printf ("Erreur d'ouverture du fichier, soit le fichier n'existe pas soit l'orthographe et/ou l'extension ne sont pas correcte.\n");
}
return 0;
}
//ajout
else if (toto == 2)
{
static void purger(void);
{
int c;
while ((c = getchar()) != '\n' && c != EOF)
{}
}
static void clean(char *nom);
{
char *p = strchr(nom, '\n');
int c;
if (p)
{
*p = 0;
}
else
{
purger();
}
}
int main(void);
{
printf("tapez votre nom :\n");
fgets(nom, sizeof(nom), stdin);
clean(nom, stdin);
printf("tapez votre prenom :");
fgets(prenom, sizeof(prenom), stdin);
clean(prenom, stdin);
printf("tapez votre adresse de messagerie :");
fgets(messagerie, sizeof(messagerie), stdin);
clean(messagerie, stdin);
printf("tapez le nom de votre service :");
fgets(service, sizeof(service), stdin);
clean(service, stdin);
printf("tapez la date de l'anomalie (sous la forme jj/mm/aaaa): ");
fgets(dateAno, sizeof(dateAno), stdin);
clean(dateAno, stdin);
printf("tapez le libelle du fichier (ce sera le nom du rapport. \n N'oubliez pas l'extension '.txt') :");
fgets(libelle, sizeof(libelle), stdin);
clean(libelle, stdin);
printf("decrivez le probleme :");
fgets(pb, sizeof(pb), stdin);
clean(pb, stdin);
printf("\n\n\n\n");
printf("\t\t ==== RAPPORT ENREGISTRE === \n\t voici les donnees qui sont dans le rapport : \n\n");
printf("\t nom: '%s'", nom);
printf("\t prenom : '%s'",prenom);
printf("\t messagerie :'%s'",messagerie);
printf("\t service :'%s'",service);
printf("\t date anomalie :'%ld'",dateAno);
printf("\t libelle :'%s'",libelle);
return 0;
}
f = fopen(libelle, "w");//ecrit dans le fichier
if (f != NULL)
{
fprintf(f, "%s\n", nom);
fprintf(f, "%s\n", prenom);
fprintf(f, "%s\n", messagerie);
fprintf(f, "%s\n", service);
fprintf(f, "%s\n", dateAno);
fprintf(f, "%s\n", pb);
fclose(f);
}
else
perror(libelle);
return 0;
}
//suppression
else if (toto == 3){
printf("tapez le nom du rapport a supprimer :\n");
scanf("%s", &sup);
printf("\t le rapport a supprimer est %s \n",sup);
}
else
printf("a bientot \n");
} |
Partager