Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.c
- // Structur_de_donnee
- //
- // Created by MacBook Pro on 19/12/2015.
- // Copyright © 2015 MacBook Pro. All rights reserved.
- //
- #include <stdio.h>
- #include "stdbool.h"
- #include "string.h"
- #include "conio.h"
- typedef struct {
- int matricule;
- double salaire;
- char Nom[25],PreNom[25];
- }fonctionnaire;
- bool matriculeTrouve(fonctionnaire *fon){
- int i=0;
- int mat;
- mat = fon[i].matricule;
- for (i=1; i<30; i++) {
- if(mat == fon[i].matricule){
- return true;
- }
- }
- return false;
- }
- void fillTab(fonctionnaire *fon){
- int i;
- printf("Remplissage du tableau :\n");
- for (i=0; i<30; i++) {
- do{
- printf("Donner le matricule du fonctionnaire: ");
- scanf("%d",&fon[i].matricule);
- }while(matriculeTrouve(fon));
- printf("Donner le salaire du fonctonnaire: ");
- scanf("%lf",&fon[i].salaire);
- getchar();
- printf("Donner le nom du fonctionnaier: ");
- gets(fon[i].Nom);
- printf("Donner le prenom du fonctionnaier: ");
- gets(fon[i].PreNom);
- }
- }
- void sort(fonctionnaire *fon){
- int i,j;
- fonctionnaire aide;
- for (i=0; i<29; i++) {
- for (j=i+1; j<30; j++) {
- if (strcmp(fon[i].Nom,fon[j].Nom)>0) {
- strcpy(aide.Nom, fon[i].Nom);
- strcpy(aide.PreNom, fon[i].PreNom);
- aide.matricule = fon[i].matricule;
- aide.salaire = fon[i].salaire;
- strcpy(fon[i].Nom, fon[j].Nom);
- strcpy(fon[i].PreNom, fon[j].PreNom);
- fon[i].matricule = fon[j].matricule;
- fon[i].salaire = fon[j].salaire;
- strcpy(fon[j].Nom, aide.Nom);
- strcpy(fon[j].PreNom, aide.PreNom);
- fon[j].matricule = aide.matricule;
- fon[j].salaire = aide.salaire;
- }
- }
- }
- }
- void printTab(fonctionnaire *fon){
- int i;
- for (i=0; i<30; i++) {
- printf("Nom: %s\nPrenom: %s\nMatricule: %d\nSalaire: %.2lf\n",((fon+i)->Nom),((fon+i)->PreNom),((fon+i)->matricule),((fon+i)->salaire));
- }
- }
- int main(int argc, const char * argv[]) {
- fonctionnaire t[30];
- fillTab(t);
- printTab(t);
- sort(t);
- printf("\nle tableau apres le triage:\n");
- printTab(t);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement