#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>


 
    struct Line{int Lnumx,Lnumy,stx,sty,enx,eny,attribute;
                struct Line *ptr,*next,*temp;
               };
    struct Word{
           char s[5];
           int count;
           struct Line *ptr;
           };
    struct Word All[37];

    FILE *fp;
    main ()
    {struct Line *last=NULL,*now;
     int stx,sty,enx,eny;
     int i,j;
        
         fp=fopen("D:/94413016/20070329/a.txt","r");
         for (i=0;i<37;i++) //因為已知txt檔的內容所以才可以這樣寫
         {
          fscanf(fp,"%s %d",All[i].s,&All[i].count);//將 count 讀入(位置)
          All[i].ptr=NULL;
                for(j=0;j<All[i].count;j++)
                {      
                 fscanf(fp,"%d%d%d%d",&stx,&sty,&enx,&eny);//印出線的兩個點
               
                 if(All[i].ptr==NULL)
                 {
                   All[i].ptr=(struct Line *)malloc(sizeof(struct Line));
                   last=All[i].ptr;
                   last->stx=stx;
                   last->sty=sty;
                   last->enx=enx;
                   last->eny=eny;
                   last->attribute=1;
                   last->ptr=NULL;
                 }else{
                         last->ptr=(struct Line *)malloc(sizeof(struct Line));
                         last=last->ptr;
                         last->stx=stx;
                         last->sty=sty;
                         last->enx=enx;
                         last->eny=eny;
                         last->attribute=0;
                         last->ptr=NULL;                     
                       }
                       now=now->ptr;              
                   }

          }
       for(i=0;i<37;i++)
        {
         now=All[i].ptr;
         while (now=NULL)
               {
                 if(now->ptr!=NULL)
                 {
                   next=now->ptr;
                   if((now->ex!=next->sx)||(now->ey!=next->sy))
                       temp=(struct Line *)malloc(sizeof(struct Line));
                       temp->sx=now->ex;             
                       temp->sy=now->ey;
                       temp->ex=now->sx;
                       temp->ey=now->sy;
                       temp->attribute=0;
                       temp->ptr=NULL;
                       temp->ptr=now->ptr;
                       now->p=temp;
                 }
                   now=now->ptr; 
               }
        }
         
        for(i=0;i<37;i++)
        {
         now=All[i].ptr;
         printf("--------------------------\n");
         printf("符號:%s\t筆劃:%d\n",All[i].s,All[i].count);
         while (now!=NULL){
               printf("(%d,%d)\t(%d,%d)\n",now->stx,now->sty,now->enx,now->eny);
              
               now=now->ptr;
               }
        }
        system("pause");
    }

arrow
arrow
    全站熱搜

    Joy 發表在 痞客邦 留言(0) 人氣()