Vous êtes sur la page 1sur 4

/* Travail pratique #1 - Partie 1 - Frederic Ouimet */ #include <stdio.h> #include <string.

h> #define EMP 30 #define LONG 25 char bidon; typedef struct { char nom[LONG]; char poste; float heures; float taux; } Employe; int Trans(char* post,char tab[]) { strupr(post); printf("%c\n",*post); switch(*post) { case 'A': strcpy(tab,"d'analyste");break; case 'P': strcpy(tab,"de programmeur");break; case 'O': strcpy(tab,"d'operateur");break; case 'S': strcpy(tab,"de secretaire");break; default: { printf("Veuillez entrer un initial valide\n"); return 0; } } } void Cut(char tab1[],char tab2[],int k) { strcpy(tab1,tab2); tab1[k]='\0'; } void Modify(char tab[]) { int i; for(i=strlen(tab)-1;i<=LONG-2;i++) tab[i]=' '; tab[LONG-1]='\0'; } int Lire(Employe tab[],const char* fichier) { int i=0; FILE* fich=fopen(fichier,"r"); if(fich==NULL) { printf("Le fichier n'a pas pu ouvrir.\n"); exit(1); }

while(!feof(fich) && i<=EMP) { fgets(tab[i].nom,LONG,fich); fscanf(fich," %c%f%f ",&tab[i].poste,&tab[i].heures,&tab[i].taux); printf("%s %c %.1f %.2f\n",tab[i].nom,tab[i].poste,tab[i].heures,tab[i]. taux); i++; } return i; } void Afficher(Employe tab[],int k) { int i,p=0; char* post,tableau[15]; printf("Veuillez entrer l'initial d'un poste (A/P/O/S)\n"); scanf("%c%c",post,&bidon); Trans(post,tableau); printf("Voici la liste des noms et des salaires pour les postes %s\n",tablea u); for(i=0;i<=k-1;i++) if(tab[i].poste==*post) { p=1; printf("%s a un salaire hebdomadaire de %.2f\n",tab[i].nom,tab[i].he ures*tab[i].taux); } if(p==0)printf("(vide)"); } void Compter(Employe tab[],int k) { int i,compte=0; float heure; char* post,tableau[15]; printf("Veuillez entrer l'initial d'un poste et un nombre d'heure (A/P/O/S)\ n"); scanf("%c%f%c",post,&heure,&bidon); if(!Trans(post,tableau))return; for(i=0;i<=k-1;i++) if(tab[i].poste==*post && tab[i].heures>heure) compte++; printf("Le nombre %ss qui travaillent plus de %.2f heures/semaine est: %d\n" ,tableau,heure,compte); } void Rechercher(Employe tab[],int k) { int i,p=0,M; char name1[LONG],name2[LONG],tableau[15]; printf("Veuillez entrer le nom de la personne recherchee\n"); scanf("%c",name1); fgets(&name1[1],LONG-1,stdin); M=strlen(name1); strupr(name1); Modify(name1); //for(i=0;i<strlen(name1);i++) //{ // printf(" '%c' ",name1[i]); //}

//getchar(); //printf("%d\n",strlen(name1)); //printf("name1 == -%s-\n",name1); for(i=0;i<=k-1;i++) { strncpy(name2,tab[i].nom,LONG); strupr(name2); //printf("%d\n",strlen(name2)); //printf("name2 == -%s-\n",name2); if(strcmp(name1,name2)==0) { Trans(&tab[i].poste,tableau); Cut(name2,tab[i].nom,M-1); printf("%s a un poste %s\n",name2,tableau); p=1; break; } } if(p==0)printf("Veuillez entrer un nom valide\n"); } void menu() { printf("0 0 00000 0 0 0 0 (A): Afficher les noms et salaires pour un p oste\n" "00 00 0 00 0 0 0 (C): Compter les gens travaillant qu'un nomb re d'heures\n" "0 0 0 00000 0 0 0 0 0 (R): Rechercher une personne dans la liste\n " "0 0 0 0 00 0 0 (W): Nettoyer la fenetre\n" "0 0 00000 0 0 000 (S): Sortir\n" "-------------------------------------------------------------------------------"); } int main() { Employe tabEmp[EMP]; char rep='n'; char* code; int N; menu(); N=Lire(tabEmp,"Employes.txt"); printf("%d\n",N); while(rep=='n') { printf("scanf switch\n"); scanf("%c%c",code,&bidon); strupr(code); printf("%c\n",*code); switch (*code) { case 'A': Afficher(tabEmp,N);break; case 'C': Compter(tabEmp,N);break; case 'R': Rechercher(tabEmp,N);break; case 'W': system("cls");menu();break; case 'S': { printf("Voulez-vous vraiment quitter le jeu? (y/n)\n"); scanf("%c%c",&rep,&bidon);

break; } default: printf("Veuillez entrer un caractere valide.\n"); } } printf("getchar return 0\n");printf("%c\n",rep);getchar(); return 0; }

Vous aimerez peut-être aussi