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
|
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_AEROPORTS 23
#if 0
#define F_AIRPORTS "C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\testlogincorrigé\\tlogcorr\\FicCaracteristiquesAeroport.txt"
#else
/* simplicite... */
#define F_AIRPORTS "airport.txt"
#endif
static void clean (char *s, FILE *fp)
{
/* search ... */
char *p = strchr (s, '\n');
if (p != NULL)
{
/* ... and kill */
*p = 0;
}
else
{
/* purge */
int c;
while ((c = fgetc(fp)) != '\n' && c != EOF)
{
}
}
}
static int sauterdeuxlignes(FILE *flot)
{
int n = 0;
int c;
while ((c = fgetc(flot)) != '\n' && c != EOF && n < 2)
{
if (c == '\n')
{
n++;
}
}
return c;
}
static void afficher_fichier(FILE *flot)
{
char chaine[128];
while (fgets(chaine, sizeof (chaine), flot) != NULL)
{
printf("%s", chaine);
}
}
int main (void)
{
int ret = EXIT_SUCCESS;
FILE*fpaero = fopen(F_AIRPORTS, "r");
if (fpaero != NULL)
{
int c = sauterdeuxlignes(fpaero);
if (c != EOF)
{
int tableau[MAX_AEROPORTS][MAX_AEROPORTS];
int tab[MAX_AEROPORTS];
{
int i = 0;
char chaine[200];
while (fgets(chaine, sizeof (chaine), fpaero) != NULL)
{
tab[i] = atoi(chaine);
i++;
}
printf ("%d airports loaded\n", i);
}
{
int i;
int j;
for (i = 0, j = 0;i < MAX_AEROPORTS;i++)
{
printf("%4d\n", tab[i]);
tableau[j][0] = tab[i];
tableau[0][j] = tab[i];
j++;
}
}
#if 0
FILE*fpcorres;
int i = 0, j = 0;
const char* tabul = "\t";
char *ID1, *ID2, *dist;
int tableau[MAX_AEROPORTS][MAX_AEROPORTS];
#endif
#if 0
if ((fpcorres = fopen("C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\testlogincorrigé\\tlogcorr\\FicCorrespondanceAeroport.txt", "r")) != NULL)
{
afficher_fichier(fpcorres);
while (fgets(chaine, sizeof chaine, fpcorres) != NULL) // c'est par la que ca foire
{
ID1 = strtok(chaine, tabul);
ID2 = strtok(NULL, tabul);
dist = strtok(NULL, tabul);
i = atoi(ID1);
j = atoi(ID2);
tableau[i][j] = atoi(dist);
}
for (i = 0;i < MAX_AEROPORTS;i++)
{
for (j = 0;j < MAX_AEROPORTS;j++)
{
printf("\t%d", tableau[i][j]);
}
}
}
else
{
fprintf(stderr, "\nerreur impo lire fich FicCaracteristiquesAero.txt\n");
return (EXIT_FAILURE);
}
#endif
}
fclose (fpaero), fpaero = NULL;
}
else
{
perror(F_AIRPORTS);
ret = EXIT_FAILURE;
}
return ret;
} |