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
| #include "stdafx.h"
#include "fonctions.h"
#include "string.h"
#include <stdlib.h>
#define MSG_1 11
#define MSG_2 12
#define MSG_3 13
#define MSG_4 14
#define JOUR 0
#define MOIS 1
#define ANNEE 2
#define TRUE 1
#define FALSE 0
void ecLectDates(int **pDate, int *pNbrLues)
{
/* encodage du nombre de jour */
int dNombreDate;
affichageMessage(MSG_4);
scanf("%d", &dNombreDate);
/* allocation mémoire du tableau */
pDate = malloc(dNombreDate * sizeof(int*));
int i;
for (i = 0; i < dNombreDate; i++)
{
pDate[i] = malloc(3 * sizeof(int));
}
/* fin allocation mémoire */
do
{
/* encodage jour */
affichageMessage(MSG_1);
scanf("%d", &pDate[*pNbrLues][JOUR]);
/* encodage mois */
affichageMessage(MSG_2);
scanf("%d", &pDate[*pNbrLues][MOIS]);
/* encodage annee */
affichageMessage(MSG_3);
scanf("%d", &pDate[*pNbrLues][ANNEE]);
(*pNbrLues)++;
} while (*pNbrLues < dNombreDate);
}
// --------------------------------------------------------------------
// fonction conversion d'un tqbleau jour/moi/annee en Jours depuis 1900
// --------------------------------------------------------------------
void convertDates(int **pDate, int *pDateConvert, int dNbrLues)
{
/* allocation mémoire du tableau pDateConvert */
pDateConvert = calloc(dNbrLues, sizeof(int));
/* fin allocation */
int i = 0;
do
{
/* jours */
pDateConvert[i] = pDate[i][JOUR];
/* mois */
if (pDate[i][JOUR] >= 2)
{
pDateConvert[i] += ((pDate[i][MOIS]) - 1) * 30;
}
/* année */
if (pDate[i][ANNEE] > 1900)
{
pDateConvert[i] += ((pDate[i][ANNEE]) - 1900) * 365;
}
i++;
} while (i < dNbrLues);
}
// ----------------------
// Fonction tri des dates
// ----------------------
void triTab(int *pDateConvert, int dNbrLues)
{
int dDesorde = TRUE;
int i, dTemp;
while (dDesorde)
{
dDesorde = FALSE;
for (i = 0; i < dNbrLues - 1; i++)
{
if (pDateConvert[i] > pDateConvert[i + 1])
{
dTemp = pDateConvert[i];
pDateConvert[i] = pDateConvert[i + 1];
pDateConvert[i + 1] = dTemp;
dDesorde = TRUE;
}
}
}
}
// ---------------------------------------------
// Conversion des valeurs en chaine de caractère
// ---------------------------------------------
void convertNumToChar(int *pDateConvert, char **pDateString, int dNbrLues)
{
int i, j, k;
for (i = 0; i < dNbrLues; i++)
{
char cTemp[15];
int dLongChaine;
_itoa(pDateConvert[i], cTemp, 10);
dLongChaine = strlen(cTemp);
for (j = 0; j < (15 - dLongChaine); j++)
{
pDateString[i][j] = '0';
}
for (k = 0; k < (15 - dLongChaine); k++)
{
pDateString[i][j] = cTemp[k];
j++;
}
}
}
// -------------------------------------------
// fonction init avec '0' d'un tableau de char
// -------------------------------------------
void iniTabChar(char **pDateString, int dNbrLues)
{
int i, j;
/* allocation mémoire du tableau */
pDateString = malloc(16 * sizeof(char));
for (i = 0; i < dNbrLues; i++)
{
pDateString[i] = malloc(dNbrLues * sizeof(char));
}
/* fin allocation mémoire */
for (i = 0; i < dNbrLues; i++)
{
for (j = 0; j < 14; j++)
{
pDateString[i][j] = '0';
}
pDateString[i][15] = '\n';
}
}
// ---------------------------------------
// fonction affichage d'un tableau de char
// ---------------------------------------
void affichageTabChar(char **pDateString, int dNbrLues)
{
int i, j;
for (i = 0; i < dNbrLues; i++)
{
for (j = 0; j < 15; j++)
{
printf("%c", pDateString[i][j]);
}
printf("\n");
}
}
// --------------------------
// fonction affichage message
// --------------------------
void affichageMessage(int MSG_ID)
{
switch (MSG_ID) {
case 11:
puts("Jour: ");
break;
case 12:
puts("Mois: ");
break;
case 13:
puts("Annee: ");
break;
case 14:
puts("Nombre de date: ");
break;
default:
break;
}
} |