| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1182 人关注过本帖
标题:【求】哪位高手帮我看一下这段程序哪出错了
只看楼主 加入收藏
youxin123
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2016-5-9
结帖率:0
收藏
 问题点数:0 回复次数:0 
【求】哪位高手帮我看一下这段程序哪出错了
#define STRLEN           60

#define DATASIZE       sizeof(EntityData)


/*-----每个实体的结构-----*/

//你可在在此添加其它的实体

//为了提高精度,变量可定义为双精度型

typedef struct tagLine{

    float x1,y1,z1;

    float x2,y2,z2;

}LINE;


typedef struct tagCircle{

    float x,y,z;

    float radius;

}CIRCLE;

/*------------------------*/


typedef union specialData{

    LINE   line;

    CIRCLE circle;

}privateData;

/*------实体的数据结构-------*/

typedef struct commonData{

    char id[STRLEN];            /*实体标识字符串*/

    char layer[STRLEN];         /*层名字符串*/

    privateData data;           /*特有数据块*/

    struct commonData *next;    /*用于构建链表*/

}EntityData;

    //定义完数据结构后,就可以用链表结构来存储实体中有用的信息了。以下程序为读取实体LINE的有关信息的代码。

/*------------------------------------------

*Entity.C 读取实体LINE部分内容。

*eryar@     02-05-08 19:52

*-------------------------------------------*/


#include <stdio.h>

#include <conio.h>

#include <stdlib.h>

#include <string.h>


#define STRLEN           60

#define DATASIZE       sizeof(EntityData)


/*-----每个实体的结构-----*/

//你可在在此添加其它的实体

typedef struct tagLine{

    float x1,y1,z1;

    float x2,y2,z2;

}LINE;


typedef struct tagCircle{

    float x,y,z;

    float radius;

}CIRCLE;

/*------------------------*/


typedef union specialData{

    LINE   line;

    CIRCLE circle;

}privateData;


typedef struct commonData{

    char id[STRLEN];            /*实体标识字符串*/

    char layer[STRLEN];         /*层名字符串*/

    privateData data;           /*特有数据块*/

    struct commonData *next;    /*用于构建链表*/

}EntityData;


/*----------函数声明部分-----------*/

void print(EntityData *entity);

/*---------------------------------*/


int main(int argc,char *argv[])

{

       int           code;

       float value;

       char codevalue[STRLEN];

      

       FILE       *dxf;

       char filename[STRLEN];

       char suffix[6] = ".dxf";


       EntityData *entity,*entity1,*entity2;


       printf("请输入DXF文件名:");

       gets(filename);

       strcat(filename,suffix);


       dxf = fopen(filename,"r");

       if(!dxf) {

              printf("打开文件出错!\n可能不存在此文件.\n");

              printf("按任意键退出...");

              getch();

              exit(0);

       }

       else {

              printf("正在读取文件...\n");

       }


       entity = entity2 = (EntityData *)malloc(DATASIZE);

              

       while(!feof(dxf)) {

              fscanf(dxf,"%d",&code);

              fscanf(dxf,"%s",codevalue);


              if(code == 2 && strcmp(codevalue,"ENTITIES")==0) {

                     while(strcmp(codevalue,"ENDSEC")) {

                            fscanf(dxf,"%d",&code);

                            fscanf(dxf,"%s",codevalue);


                            if(code == 0 && strcmp(codevalue,"LINE")==0) {

                                   entity1 = (EntityData *)malloc(DATASIZE);


                                   strcpy(entity1->id,codevalue);


                                   fscanf(dxf,"%d",&code);

                                                                                                        

                                   while(code) {

                                          switch(code) {

                                          case 8:

                                                 fscanf(dxf,"%s",codevalue);

                                                 fscanf(dxf,"%d",&code);

                                                 strcpy(entity1->layer,codevalue);

                                                 break;

                                          case 10:

                                                 fscanf(dxf,"%f",&value);

                                                 fscanf(dxf,"%d",&code);

                                                 entity1->data.line.x1 = value;

                                                 break;

                                          case 20:

                                                 fscanf(dxf,"%f",&value);

                                                 fscanf(dxf,"%d",&code);

                                                 entity1->data.line.y1 = value;

                                                 break;

                                          case 30:

                                                 fscanf(dxf,"%f",&value);

                                                 fscanf(dxf,"%d",&code);

                                                 entity1->data.line.z1 = value;

                                                 break;

                                          case 11:

                                                 fscanf(dxf,"%f",&value);

                                                 fscanf(dxf,"%d",&code);

                                                 entity1->data.line.x2 = value;

                                                 break;

                                          case 21:

                                                 fscanf(dxf,"%f",&value);

                                                 fscanf(dxf,"%d",&code);

                                                 entity1->data.line.y2 = value;

                                                 break;

                                          case 31:

                                                 fscanf(dxf,"%f",&value);

                                                 fscanf(dxf,"%d",&code);

                                                 entity1->data.line.z2 = value;

                                                 break;

                                          default: {

                                                 fscanf(dxf,"%s",codevalue);

                                                 fscanf(dxf,"%d",&code);

                                                         }

                                          }

                                   }

                                   

                                   entity2->next = entity1;

                                   entity2 = entity1;

                            }

                     }

                     entity2->next = NULL;

              }

       }


       entity = entity->next;            //第一个实体区为空,所以使头指针移向下一个实体

       print(entity);                        //输出链表


    printf("\nPress any key to halt...");

    getch();

    return 0;

}


//输出链表

void print(EntityData *entity)

{

       int i=0;

       EntityData *pointer;


       pointer = entity;


       if(pointer != NULL) {

              do{

                     i++;

                     pointer = pointer->next;

              }while(pointer != NULL);

       }


       printf("\nOutput LinkList:");

       printf("\nDXF文件中总共有%d条直线:\n",i);


       i = 1;

       pointer = entity;


       if(pointer != NULL) {

              do{

                     printf("第%d条直线:\n",i);

                     printf("X1=%f\tY1=%f\tZ1=%f\n",pointer->data.line.x1,

                            pointer->data.line.y1,pointer->data.line.z1);

                     printf("X2=%f\tY2=%f\tZ2=%f\n",pointer->data.line.x2,

                            pointer->data.line.y2,pointer->data.line.z2);


                     pointer = pointer->next;

                     i++;

              }while(pointer !=NULL);

       }
2016-05-22 12:46
快速回复:【求】哪位高手帮我看一下这段程序哪出错了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.046079 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved