【发布时间】:2021-04-12 10:37:31
【问题描述】:
如何读取 ASCII STL 文件 cubea.stl 以将其打印到文件 output.dat?
我写了一部分程序,但是这个 main.cpp 不起作用。
我可能在 main.cpp 中遗漏了一些程序。
main.cpp
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cubea.stl"
#include "output.dat"
#define MAXLINE 128
#define PSLD "SOLID"
#define PNML "FACET NORMAL"
#define POUT "OUTER LOOP"
#define PVTX "VERTEX"
#define PELP "ENDLOOP"
#define PEFC "ENDFACET"
#define PESL "ENDSOLID"
#define FINAME "cubea.stl"
#define FONAME "output.dat"
#include "cubea.stl"
#include "output.dat"
int main();
int main() {
char *cp;
float n[3], v[3][3];
FILE *fin, *fout;
char txtline[MAXLINE];
if ((fin = fopen(FINAME, "r")) == NULL) exit(1);
if ((fout = fopen(FONAME, "w")) == NULL) exit(2);
while ((cp = fgets(txtline, MAXLINE, fin)) != NULL);
{
if (strstr(cp, PSLD) == cp)
fprintf(fout, "%s", cp);
else if (strstr(cp, PNML) == cp)
{
cp += strlen(PNML);
sscanf(cp, "%f %f %f", &n[0], &n[1], &n[2]);
fprintf(fout, "%s %f %f %f\n", PNML, n[0], n[1], n[2]);
}
}
fclose(fin);
fclose(fout);
}
【问题讨论】:
-
请选择一种语言。 C 和 C++ 是两种不同的语言。然后请解释你的代码做什么以及它与它应该做什么有什么不同
-
作为这里的新用户,也可以使用tour 并阅读How to Ask。
-
stl和dat文件的内容是什么?您将这两个文件都用作代码的包含文件(甚至两次)和输入/输出文件。我有点怀疑这会飞。
-
我认为您需要了解
#include的作用。 -
“不起作用”对正在发生的事情没有有用的描述。请编辑您的问题以提供失败的方式。还请包括在以前的 cmets 中已经请求的缺失信息,例如输入、输出、预期输出...