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
| #include <stdio.h>
#include <stdlib.h>
struct gri
{
int n,nl,nr,nb,nt,c;
float x,y,dl,dr,db,dt;
struct gri *next, *next1, *next2;
};
typedef struct gri GRI;
GRI * geo;
int main(void)
{
char inputfile[80];
int taille, i;
FILE *fp;
//Lecture du nom de fichier
puts("Enter file name:");
scanf("%80s", inputfile);
fp = fopen(inputfile, "r");
//initialisation du pointeur
GRI *g=NULL;
GRI *grd=NULL;
//allocation de memoire
grd=calloc(1,sizeof(GRI));
if(grd==NULL)
{
exit(1);
}
g=grd;
fscanf(fp,"%d",&taille);
geo=calloc(taille,sizeof(GRI));
//remplissage de ma structure et liste chainee
i=0;
while (fp!=NULL)
{
fscanf(fp,"%d %d %d %d %d %d %f %f",&geo[i].n,&g->next1->n,&g->next2->n,&geo[i].nl,&geo[i].nr,&geo[i].nb,&geo[i].nt,&geo[i].x,&geo[i].y);
i++;
printf("%d\t%d\n",g->next1->n,g->next2->n);
g->next=(GRI*)calloc(1,sizeof(GRI));
g=g->next;
if (feof(fp) || ferror(fp))
{
break;
}
}
system("PAUSE");
return 0;
} |
Partager