#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <math.h>
#include <ctime>
#include <thread>
#include <Windows.h>
using namespace std;
bool compare(const char *s, const char *q, int n)
{
int i = 0;
while (i<n)
{
if (q[i++] != s[i++])
return false;
}
if (i = n && (s[n] - ' ' == 0 || s[n] - '\n' == 0 || s[n] == NULL))
return true;
else
return false;
}
int Triangle_num(char* fname)
{
FILE *fp;
if ((fp = fopen(fname, "r ")) == NULL)
{
printf("Can't open file");
exit(1);
}
int npoint = 0; //点个数
int count = 0; //三角面片个数
while (!feof(fp)) //feof()函数为判断文件是否结束,C语言
{
char f[256];
fgets(f, 256, fp);
if (compare(strtok(f, " "), "vertex ", 6))
{
if (++npoint == 3)
{
count++;
npoint = 0;
}
}
}
fclose(fp);
return count;
}
void main()
{
char *a, *b;
a = new char[50];
b = new char[50];
a = "C:\\Users\\Huan\\Desktop\\stl\\12workpiece.STL";
b = a;
Triangle_num(a);
system("pause");
delete[] b;//增加delete之后出现报错
}
内存删除出现问题,在delete[] 处程序运行中断,希望大家能帮我看一下问题出在哪里。
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- shen_wei 2017-03-14 08:53关注
char *a, *b; a = new char[50]; b = new char[50]; strcpy(a,"C:\\Users\\Huan\\Desktop\\stl\\12workpiece.STL"); b = a; // a 和 b 指向同一块区域 //Triangle_num(a); //system("pause"); delete a; 释放其中之一就可以
解决 无用评论 打赏 举报
悬赏问题
- ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
- ¥88 找成都本地经验丰富懂小程序开发的技术大咖
- ¥15 如何处理复杂数据表格的除法运算
- ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
- ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
- ¥200 uniapp长期运行卡死问题解决
- ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
- ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
- ¥15 乘性高斯噪声在深度学习网络中的应用
- ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决