everything seems to go fine except when i get to the search. either the program runs with a runtime error ,and it cannot be excuted.
/*****************************************************
Program Filename : post.cpp
Date : May 27, 2007
Purpose : NC code convert
Input from : a cls data file
Output to : a NC data file
*****************************************************/
// Preprocessor directives:
#include <iostream>
#include <string>
#include <cstring>
#include<cmath>
#include<fstream>
#include<cstdlib>
#include<conio.h>
#include<process.h>
using namespace std;
const float PI =float (3.14159); // define PI value
void main()
{
// Variable declarations:
char infile[20],outfile[20]; //定义外部文件名
fstream outdata,indata; //定义内部文件名
// Function prototypes:
void NCcode_convert(fstream &,fstream &);
// Function body:
cout<<"\nPlease enter the external cut file to Post: "; //提示输入CLS文件路径
cin.getline(infile,20); //以字符变量形式存放外部文件名
indata.open(infile,ios::in); //打开文件
if(indata.fail()) //检查文件打开成功与否
{
cerr<<"\n***>Open error while opening input file "<<infile<<endl;
exit(-1);
}
cout<<"\nPlease enter the name of Post file: ";
cin.getline (outfile,20);
outdata.open(outfile,ios::out);
if(outdata.fail())
{
cerr<<"\n***> Open error while opening input file "<<outfile;
exit(-1);
}
cout<<"\nPost from"<<infile<<" to "<<outfile<<" in the process...\n";
NCcode_convert(indata,outdata);
cout<<"\nPost process completed..."<<endl;
indata.close(); //文件关闭
outdata.close();
}
//......................................................................
/******************************************************
Function Name : NCcode_convert
Purpose : convert cls code to NCcode
Called by : main
******************************************************/
void NCcode_convert(/* I-O */ fstream &indata,fstream &outdata)
{
// Local variable declarations:
char *ptr; //定义指针变量ptr
char *temp1= "GOTO", *temp2 = "FEDRAT", *temp3 = "CIRCLE"; // 刀位文件命令
char *temp4="LOAD/TOOL",*temp5="RAPID",*temp6="SPINDL";
char ch;
char axe[10];
char str[128];
int n,m,sz,f,tempf=0;
int nnn,nn[8],t,t01;
int flag=1;
int N=1,n02=0;
float x,y,z,i,j,k,a,c,fx,fy,fz,fa,fc;
float ForthAxisMin,ForthAxisMax,FifthAxisMin,FifthAxisMax;
float tempa=-999.0;
// Function body:
while(!indata.eof()) //通过循环从文件中读取数据
{
indata>>str; //从文件中读取一条记录并将内容存放到变量str
m=0;
ptr=strstr(str,temp1); //读取 FEDRAT m=1
if(ptr!=NULL)
m=1;
ptr=strstr(str,temp2); //读取 GOTO m=2
if(ptr!=NULL)
m=2;
ptr=strstr(str,temp3); //读取 CIRCLE m=3
if(ptr!=NULL)
m=3;
ptr=strstr(str,temp4); //读取 SPINDL m=4
if(ptr!=NULL)
m=4;
switch(m)
{
case 1: //读出FEDRAT中的值
{
sz=strlen(str);
t=1;
for(nnn=0;nnn<=sz;nnn++)
{
ch=str[nnn];
if((ch=='/')||(ch==','))
{
nn[t]=nnn;
t++;
}
}
n02+=1;
for(nnn=1;nnn<t;nnn++)
{
int cn1,op=0; //数组和计数器
if(nnn==2&&n02==1)
{
for(cn1=(nn[nnn]+1);cn1<(sz-1);cn1++)
{
axe[op]=str[cn1];
op++;
}
f=atof(axe);
}
if(nnn==1&&n02>=2)
{
for(cn1=(nn[nnn]+1);cn1<(sz-1);cn1++) //FEDRAT中的值第二次以上出现时
{
axe[op]=str[cn1];
op++;
}
f=atof(axe);
}
}
flag=2;
break;
}
case 2: //读出GOTO中的X,Y,Z,I,J,K值
{
sz=strlen(str);
t=1;
for(nnn=0;nnn<=sz;nnn++)
{
ch=str[nnn];
if((ch=='/')||(ch==','))
{
nn[t]=nnn;
t++;
}
}
for(nnn=1;nnn<t;nnn++)
{
int cn1=0,op=0;
if(nnn<=6)
switch(nnn)
{
case 1:
{
for(cn1=(nn[nnn]+1);cn1<(nn[nnn+1]-1);cn1++) //X data
{
axe[op]=str[cn1];
op++;
}
x=atof(axe);
break;
}
case 2:
{
for(cn1=(nn[nnn]+1);cn1<(nn[nnn+1]-1);cn1++) //Y data
{
axe[op]=str[cn1];
op++;
}
y=atof(axe);
break;
}
case 3:
{
for(cn1=(nn[nnn]+1);cn1<(nn[nnn+1]-1);cn1++) //Z data
{
axe[op]=str[cn1];
op++;
}
z=atof(axe);
break;
}
case 4:
{
for(cn1=(nn[nnn]+1);cn1<(nn[nnn+1]-1);cn1++) //I data
{
axe[op]=str[cn1];
op++;
}
i=atof(axe);
break;
}
case 5:
{
for(cn1=(nn[nnn]+1);cn1<(nn[nnn+1]-1);cn1++) //J data
{
axe[op]=str[cn1];
op++;
}
j=atof(axe);
break;
}
case 6:
{
for(cn1=(nn[nnn]+1);cn1<(sz-1);cn1++) //K data
{
axe[op]=str[cn1];
op++;
}
k=atof(axe);
break;
}
} //end switch(nnn)
} //end for
ForthAxisMin=0;
ForthAxisMax=120; //绕X转角
FifthAxisMin=0;
FifthAxisMax=360; //绕Z转角
// A、C转角计算
if (z>0)
fa = atan( sqrt(x*x+y*y)/z);
if (z=0)
fa = 90;
if (z<0 || fa<120)
fa = 90 - atan(sqrt(x*x+y*y)/z);
if ((x>0 && y>=0)||(x>0 && y<=0))
fc=90+atan(y/x);
if ((x<0 && y>=0)||(x<0 && y<=0))
fc = 270+atan(y/x);
if (x=0 && y<=0)
fc = 0;
if (x=0 && y>0)
fc = 180;
// 机床运动坐标X、Y、Z计算
fx = x*cos(fc) + y*sin(fc);
fy = -x*sin(fc)*cos(fa) + y*cos(fc)*cos(fa) + z*sin(fa);
fz = x*sin(c)*sin(fa) - y*cos(fc)*sin(fa) + z*cos(fa);
if(flag==2)
{
outdata<<fixed;
outdata.precision (3);
outdata<<"\n"<<"G01"<<" X"<<fx<<" Y"<<fy<<" Z"<<fz<<" A"<<fa<<" C"<<fc<<" F"<<f;
}
else
{
outdata<<fixed;
outdata.precision (3);
outdata<<"\n"<<" X"<<fx<<" Y"<<fy<<" Z"<<fz<<" A"<<fa<<" C"<<fc;
}
N=N+1;
flag=1;
break;
} //end case 2
} //end switch
} //end while
}
and need your help, thank u.