问题遇到的现象和发生背景
编写导航星历文件读入的时候,生成解决方案没有错误,但调试和运行都无法结束
问题相关代码,请勿粘贴截图
int Nread(int &num)
{
ifstream ifs;
ifs.open("brdm1120.21p", ios::_Nocreate);
if (!ifs.is_open())
{
cout << "文件打开失败" << endl;
return -1;
}
cout << "文件打开成功" << endl;
const int max = 100;//每行字符数
char line[max];
//计算星历数
int line1 = 0;
while (1)
{
if (strstr(line, "END OF HEADER") != NULL)
break;
}
while (1) {
if (strstr(line, "RO1") != NULL)
break;
GPSTIME *pGpsTime = new GPSTIME[num];
NfileRead *ephlst = new NfileRead[num];
int PRN;
char column_1[100];
int year, mon, day, hour, min;
double sec;
double a0, a1, a2;
double iode, Crs, delta_n, M0;
double Cuc, e, Cus, sqrt_a;
double toe, Cic, OMG0, Cis;
double i0, Crc, omgs, OMG;
double idot, code, GPS_Week, L2_P;
double SVaccuracy, SVhealth, TGD, IODC;
double messeagetime, fitinterval;
char str[max];
ifs.getline(str, max, '\n');//读取第一行数据
sscanf(str, "%s %d %d %d %d %d %d %lf %lf %lf", column_1, &year, &mon, &day, &hour, &min, &sec, &a0, &a1, &a2);
int prn = 0;
sscanf(column_1, "G%d", &prn);
cout << hour << " " << min << " " << sec << " " << prn << endl;
ifs.getline(str, max, '\n');//读取第二行数据
sscanf(str, "%lf %lf %lf %lf", &iode, &Crs, &delta_n, &M0);
ifs.getline(str, max, '\n');//读取第三行数据
sscanf(str, "%lf %lf %lf %lf", &Cuc, &e, &Cus, &sqrt_a);
ifs.getline(str, max, '\n');//读取第四行数据
sscanf(str, "%lf %lf %lf %lf", &toe, &Cic, &OMG0, &Cis);
ifs.getline(str, max, '\n');//读取第五行数据
sscanf(str, "%lf %lf %lf %lf", &i0, &Crc, &omgs, &OMG);
ifs.getline(str, max, '\n');//读取第六行数据
sscanf(str, "%lf %lf %lf %lf", &idot, &code, &GPS_Week, &L2_P);
ifs.getline(str, max, '\n');//读取第七行数据
sscanf(str, "%lf %lf %lf %lf", &SVaccuracy, &SVhealth, &TGD, &IODC);
ifs.getline(str, max, '\n');//读取第八行数据
sscanf(str, "%lf %lf", &messeagetime, &fitinterval);
//数据放入数组
ephlst[line1].year = year;
ephlst[line1].mon = mon;
ephlst[line1].day = day;
ephlst[line1].hour = hour;
ephlst[line1].min = min;
ephlst[line1].sec = sec;
ephlst[line1].PRN = prn;
ephlst[line1].a0 = a0;
ephlst[line1].a1 = a1;
ephlst[line1].a2 = a2;
ephlst[line1].iode = iode;
ephlst[line1].Crs = Crs;
ephlst[line1].delta_n = delta_n;
ephlst[line1].M0 = M0;
//&Cuc, &e, &Cus, &sqrt_a
ephlst[line1].Cuc = Cuc;
ephlst[line1].e = e;
ephlst[line1].Cus = Cus;
ephlst[line1].sqrt_a = sqrt_a;
//&toe, &Cic, &OMG0, &Cis
ephlst[line1].toe = toe;
ephlst[line1].Cic = Cic;
ephlst[line1].OMG0 = OMG0;
ephlst[line1].Cis = Cis;
//&i0, &Crc, &omgs, &OMG
ephlst[line1].i0 = i0;
ephlst[line1].Crc = Crc;
ephlst[line1].omgs = omgs;
ephlst[line1].OMG = OMG;
ephlst[line1].idot = idot;
line1++;
}
ifs.close();
}
我的解答思路和尝试过的方法
以为是数据过长,电脑配置导致的错误,只保留GPS数据,运行依旧无法结束
我想要达到的结果
头文件不读入,只从END OF HEADER开始,文件只读入GPS数据和北斗数据并且放入指定数组
文件读入开始部分:
GPS数据结尾:
北斗数据开头: