多边形读取
发布日期:2021-05-10 05:58:53 浏览次数:29 分类:精选文章

本文共 2028 字,大约阅读时间需要 6 分钟。

���������������������

������������

#include 
#include
#include

������������

#define DATA_SIZE 1024
typedef struct {
double x;
double y;
} Point;
typedef struct {
char name[20];
Point point1;
union {
Point point2;
double Radius;
} cate;
struct Polygon *next;
} Polygon;

������������

int main() {
FILE *fp = fopen("data.txt", "r");
Polygon *L = (Polygon *)malloc(sizeof(Polygon));
L->next = NULL;
Polygon *p = L;
char s[50];
double x1, y1, x2, y2;
fscanf(fp, "%s", s);
while (strcmp(s, "END") != 0) {
Polygon *q = (Polygon *)malloc(sizeof(Polygon));
q->next = NULL;
strcpy(q->name, s);
if (!strcmp(s, "LINE")) {
// ������������������
fscanf(fp, "%lf%lf%lf%lf",
&x1, &y1,
&x2, &y2);
} else if (!strcmp(s, "RECT")) {
// ���������������������
fscanf(fp, "%lf%lf%lf%lf",
&x1, &y1,
&x2, &y2);
} else if (!strcmp(s, "CIRCLE")) {
// ���������������
fscanf(fp, "%lf%lf%lf",
&x1, &y1,
&Radius);
}
// ������������
// ��������������� `&` ������������������
printf("%.2f %.2f %.2f %.2f\n", x1, y1, x2, y2);
printf("\n\n");
fgetc(fp); // ������������������
p->next = q;
p = q;
// ���������������������
fscanf(fp, "%s", s);
}
fclose(fp);

������������������

1. ���������������

  • stdio.h���������������������������
  • stdlib.h���������������������
  • string.h������������������

2. ������������������

  • Point ���������������������������
  • Polygon ������������������������������������������������������������������

3. ���������������

  • ������������������
  • ������������������������
  • ������������������
  • ������������������
  • ������������������������
  • ������������������
  • ������������������
  • 上一篇:【Java-1】JDK与Eclipse安装与环境变量设置
    下一篇:静态列级、元组、关系,动态列级、元组实例区别

    发表评论

    最新留言

    第一次来,支持一个
    [***.219.124.196]2025年04月09日 08时47分41秒