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
|
#include "stdio.h"
#include "stdafx.h"
#include "string.h"
#include "stdlib.h"
#include "gestionnaire.h"
#define TBLOC 9 // Macro private
void Req_Msg (char **pMsg); // les prototypes private doivent se trouver dans le fichier .cpp ou ils sont utilisés.
void AddBloc (char ***ppTabDynamique,int *dPosMax); // les prototypes private doivent se trouver dans le fichier .cpp ou ils sont utilisés.
//static char *(*tTab)[] ; // Pointeur sur un tableau de pointeur de char
static char **tTab;
static int dPosCour = 0 ;
static int dPosMax = 0 ;
// Initialisation du tableau ***************
void GmInit(int *pRC)
{
if (dPosCour < 1) // si le tableau est vide
{
dPosCour = 0;
*pRC = GM_OK;
printf("\n Fin GmInit, Le tableau etait vide \n");
printf("\n Le tableau dispose de %d places \n", dPosMax);
}
else // si le tableau n'est pas vide
{
int dIndex = 0 ;
for(dIndex = 0 ; dIndex < dPosCour ; dIndex++)
{
free(tTab[dIndex]);
}
*pRC = GM_ERROR;
dPosCour = 0;
printf("\n Fin GmInit, Le tableau a ete reinitialiser \n");
printf("\n Le tableau dispose de %d places \n", dPosMax);
}
}
// Sous Fonction pour ajout de message, demande le message..
void Req_Msg (char **pMsg)
{
printf("\n on entre dans la fonction Req_Msg");
char sChaine[500];
int dLChaine ;
char *tTabMsg ;
printf("\n Entrez votre chaine : \n");
fflush(stdin);
scanf("%s", sChaine);
fflush(stdin);
printf("\n Votre chaine stocke dans sChaine est : %s", sChaine);
dLChaine = strlen(sChaine);
tTabMsg = (char *)malloc(dLChaine * sizeof(char));
strcpy(tTabMsg, sChaine);
*pMsg = tTabMsg ;
}
// sous fonction pour allocation dynamique du tableau contenant les adresse pTabDynamAdress
void AddBloc (char ***ppTabDynamique,int *dPosMax)
{
printf("\n on entre dans la fonction AddBloc \n");
char *pTab ;
pTab = (char *)malloc((*dPosMax + TBLOC) * sizeof(char));
*ppTabDynamique = &pTab;
printf("\n *dPosMax + TBLOC-1 = %d \n", *dPosMax + TBLOC - 1);
*dPosMax = *dPosMax + TBLOC -1 ;
printf("\n TABLEAU ALLOUE DYNAMIQUEMENT \n");
printf("\n ppTabDynamique = %d \n", ppTabDynamique);
if (ppTabDynamique == NULL)
{
printf("ERREUR ALLOCATION DYNAMIQUE");
}
}
// Ajout d'un message *****************/
void gmAdd (char *pMsg, int *pRC)
{
printf("\n on entre dans la fonction gmAdd \n");
printf("\n dPositionCour = %d \n", dPosCour);
printf("\n dPositionMax = %d \n", dPosMax);
printf("\n PLACES RESTANTES AVANT INSERTION: %d places", dPosMax-dPosCour);
int dLong ;
if (dPosCour > dPosMax - 1)
{
printf("\n LIGNE avant de rentrer dans AddBlock");
AddBloc (&tTab, &dPosMax);
printf("\n LIGNE apres etre sorti de AddBlock");
}
dLong = strlen(pMsg);
printf("\n Position Courante av printf = %d", dPosCour);
printf("\n Longueur dLong = %d", dLong);
printf("\n Chaine en utilisant le pointeur msg= %s", pMsg);
tTab[dPosCour]= (char *)malloc((dLong + 1) * sizeof(char));
strcpy (tTab[dPosCour], pMsg);
printf("\n Chaine en utilisant le pointeur tTab[dPosCour] = %s", tTab[0]);
//printf("\n Chaine en utilisant le pointeur tTab[dPosCour] = %s", tTab[0]);
printf("\n Position Courante apres printf = %d", dPosCour);
dPosCour++;
printf("\n PLACES RESTANTES APRES INSERTION: %d places", dPosMax-dPosCour);
printf("\n Position Courante apres ++ = %d", dPosCour);
}
// Affichage des messages ****************
void gmDisplay (int *pRC)
{
if(dPosCour > 0)
{
printf("\n Chaine en utilisant le pointeur tTab[dPosCour] = %s", tTab[0]);
printf("\n on entre dans la fonction GmDisplay \n");
printf("\n Position Courante = %d", dPosCour);
printf("\n ** AFFICHAGE TABLEAU ** \n");
printf("\n Chaine en utilisant le pointeur tTab[dPosCour] = %s", tTab[0]);
int dIndex = 0;
for (dIndex = 0 ; dIndex < dPosCour; dIndex++)
{
printf("\n %s",tTab[dIndex]);
}
*pRC = GM_OK;
}
else
{
printf("\n ** LE TABLEAU EST VIDE ** \n");
}
} |
Partager