#include <stdio.h>
#include <tchar.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
using namespace std;
#pragma warning(disable:4996)
#define pi 3.1415926
typedef struct point {
int ID; //点的ID
double x, y, z; //点的x,y,z
}Point;
/* TIN - 点三角形组织方式 */
typedef struct triangle_PT {
int ID; //三角形的ID
int A, B, C; //三角形的三个顶点
}Triangle_PT;
typedef struct TIN_PT
{
Point *p; //点集
Triangle_PT *tris; //边集
int pointNum; //点数
int triNum; //三角形个数
}TIN_PT; //点、三角形组织方式
int ReadTIN_PTFile(char *filename, TIN_PT *tin)
{
int i,j;
char fp[10000];
tin->p = (Point *)malloc(sizeof(Point) * tin->pointNum);//这一步麻烦讲解一下是什么
ifstream dm(filename);
if (!dm)
{
printf("cannot got it\n");
exit(0);
}
for (j = 1; j < 30; j++)
{
dm.getline(fp, 128, '\n');
for (i = 1; i < 30; i++)
{
if (fp[i] == '\0')
break;
if (fp[i] == ',')
fp[i] = ' ';
}
sscanf_s(fp, "%s %lf %lf %lf", &tin->p[j].ID, &tin->p[j].x, &tin->p[j].y, &tin->p[j].z);
}
return 1;
}
int main()
{
TIN_PT tin1;
ReadTIN_PTFile("C:\\Users\\86159\\Desktop\\get\\TIN数据.txt", &tin1);//自行修改路径
system("pause");
return 0;
}
无法读取文件,老是中断,不知道问题出在哪里,麻烦讲解一下(标注的地方也讲解一下)
文件网盘(供调试使用):链接: https://pan.baidu.com/s/1Jvz5zeaG1FPeDGTBWPc_Cg?pwd=cg8j
提取码: cg8j