#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#define STRLEN 60
#define DATASIZE sizeof(EntityData)
/*-----每个实体的结构-----*/
//你可在在此添加其它的实体
typedef struct tagSpLine{
float x, y, z;
int pole;//节点
int control;//控制点
float weight;//权重
float knots[100];
}LINE;
/*------------------------*/
typedef union specialData{
LINE spline;
}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;
int k=0;
float value;
char codevalue[STRLEN];
FILE *dxf;
char filename[STRLEN];
EntityData *entity, *entity1, *entity2;
printf("请输入DXF文件名:");
dxf = fopen("E:\\yt.dxf", "r");
if (!dxf)
{
printf("打开文件出错!\n可能不存在此文件.\n");
printf("按任意键退出...");
getchar();
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, "SPLINE") == 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 40:
fscanf(dxf, "%f", &value);
fscanf(dxf, "%d", &code);
entity1->data.spline.knots[k++] = value;//节点值
break;
case 41:
fscanf(dxf, "%f", &value);
fscanf(dxf, "%d", &code);
entity1->data.spline.weight = value;//权重
break;
case 10:
fscanf(dxf, "%f", &value);
fscanf(dxf, "%d", &code);
entity1->data.spline.x = value;
break;
case 20:
fscanf(dxf, "%f", &value);
fscanf(dxf, "%d", &code);
entity1->data.spline.y = value;
break;
case 30:
fscanf(dxf, "%f", &value);
fscanf(dxf, "%d", &code);
entity1->data.spline.z = value;
break;
case 72:
fscanf(dxf, "%f", &value);
fscanf(dxf, "%d", &code);
entity1->data.spline.pole = value;//节点数
break;
case 73:
fscanf(dxf, "%f", &value);
fscanf(dxf, "%d", &code);
entity1->data.spline.control = 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...");
getchar();
return 0;
}
//输出链表
void print(EntityData *entity)
{
int i = 0;
int k = 0;
int j;
EntityData *pointer;
pointer = entity;
FILE *fpw = fopen("E:\\result.txt", "w");
if (pointer != NULL)
{
do{
i++;
pointer = pointer->next;
} while (pointer != NULL);
}
printf("\nOutput LinkList:");
printf("\nDXF文件中总共有%d条直线\n", i);
//i = 1;
pointer = entity;
/*直线*/
char buf[100] = { 0 };
if (pointer != NULL)
{
do{
//printf("第%d条直线:\n", i);
/*打印到桌面*/
//printf("权重%f\t节点值%f\t节点数%d\t控制点数%d\n", pointer->data.spline.weight, pointer->data.spline.knots[k++], pointer->data.spline.pole, pointer->data.spline.control);
//printf("X %f\tY %f\tZ %f\n", pointer->data.spline.x, pointer->data.spline.y, pointer->data.spline.z);
for (j = 0; j < pointer->data.spline.pole; j++)
{
printf("knots%.16f\n", pointer->data.spline.knots[k++]);
}
pointer = pointer->next;
i++;
} while (pointer != NULL);
}
fclose(fpw);
}
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#define STRLEN 60
#define DATASIZE sizeof(EntityData)
/*-----每个实体的结构-----*/
//你可在在此添加其它的实体
typedef struct tagSpLine{
float x, y, z;
int pole;//节点
int control;//控制点
float weight;//权重
float knots[100];
}LINE;
/*------------------------*/
typedef union specialData{
LINE spline;
}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;
int k=0;
float value;
char codevalue[STRLEN];
FILE *dxf;
char filename[STRLEN];
EntityData *entity, *entity1, *entity2;
printf("请输入DXF文件名:");
dxf = fopen("E:\\yt.dxf", "r");
if (!dxf)
{
printf("打开文件出错!\n可能不存在此文件.\n");
printf("按任意键退出...");
getchar();
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, "SPLINE") == 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 40:
fscanf(dxf, "%f", &value);
fscanf(dxf, "%d", &code);
entity1->data.spline.knots[k++] = value;//节点值
break;
case 41:
fscanf(dxf, "%f", &value);
fscanf(dxf, "%d", &code);
entity1->data.spline.weight = value;//权重
break;
case 10:
fscanf(dxf, "%f", &value);
fscanf(dxf, "%d", &code);
entity1->data.spline.x = value;
break;
case 20:
fscanf(dxf, "%f", &value);
fscanf(dxf, "%d", &code);
entity1->data.spline.y = value;
break;
case 30:
fscanf(dxf, "%f", &value);
fscanf(dxf, "%d", &code);
entity1->data.spline.z = value;
break;
case 72:
fscanf(dxf, "%f", &value);
fscanf(dxf, "%d", &code);
entity1->data.spline.pole = value;//节点数
break;
case 73:
fscanf(dxf, "%f", &value);
fscanf(dxf, "%d", &code);
entity1->data.spline.control = 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...");
getchar();
return 0;
}
//输出链表
void print(EntityData *entity)
{
int i = 0;
int k = 0;
int j;
EntityData *pointer;
pointer = entity;
FILE *fpw = fopen("E:\\result.txt", "w");
if (pointer != NULL)
{
do{
i++;
pointer = pointer->next;
} while (pointer != NULL);
}
printf("\nOutput LinkList:");
printf("\nDXF文件中总共有%d条直线\n", i);
//i = 1;
pointer = entity;
/*直线*/
char buf[100] = { 0 };
if (pointer != NULL)
{
do{
//printf("第%d条直线:\n", i);
/*打印到桌面*/
//printf("权重%f\t节点值%f\t节点数%d\t控制点数%d\n", pointer->data.spline.weight, pointer->data.spline.knots[k++], pointer->data.spline.pole, pointer->data.spline.control);
//printf("X %f\tY %f\tZ %f\n", pointer->data.spline.x, pointer->data.spline.y, pointer->data.spline.z);
for (j = 0; j < pointer->data.spline.pole; j++)
{
printf("knots%.16f\n", pointer->data.spline.knots[k++]);
}
pointer = pointer->next;
i++;
} while (pointer != NULL);
}
fclose(fpw);
}