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
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define CMAX 400
#define LMAX 400
#define MAX_CHAR_PER_LINE 1650
#define SEP " "
#define PATH "fichier.txt"
int main(int argc, char* argv[])
{
FILE* m_File;
int i = 0;
int j;
int Tab[LMAX][CMAX];
char szbuff[MAX_CHAR_PER_LINE];
char* token = NULL;
m_File = fopen(PATH,"rt");
if(!m_File) return 1;
while(!feof(m_File) && i < LMAX)
{
j = 0;
// On récupere la ligne courante du fichier
fgets(szbuff,MAX_CHAR_PER_LINE,m_File);
// On decoupe la ligne selon le charactere de séparation EP (" ")
token = strtok(szbuff,SEP);
while(token != NULL && j < CMAX)
{
// On stocke la valeur lue dans le tableau
Tab[i][j] = atoi(token);
// On lit l'element suivant retourner par strtok
token = strtok(NULL,SEP);
// On incremente le compteur des ordonnées
j++;
}
// On incrémente le compteur des abscisses
i++;
}
//affichage
int x;
for(x=0;x<i;x++)
{
int y;
for( y=0;y<j;y++)
{
printf("%i\t",Tab[x][y]);
}
printf("\n");
}
}//fin main |