我对这些东西还是很陌生。我正在尝试为我的高级项目编写一个简单的解析器。我大部分时间都在工作,但是当我让它解析越来越长的文件时,它开始给我一个访问冲突错误。这是我正在解析的示例(.txt 文件中的 APRS 数据包)
> # 1342977832 Sun Jul 22 11:23:51 2012 WB1SAR-11>APT3A2,WIDE1-1,WIDE2-1:/172347h4014.07N/11004.38WO227/015/A=047664/HARBOR
在做了一些研究之后,问题显然出在带有指针的 for 循环中,但我不知道该怎么做。谢谢你的帮助。代码是: int GetLat(char* parse_test, char* line_string) { int B_GPS_lat_deg = 0; 浮动 B_GPS_lat_min = 0;
parse_test = strstr(line_string,"h"); //the latitude starts after the time. time ends with "h".
char deg_buffer[2]; // buffer to use with atof() which converts an array to a float
for (int k = 0; k < 2; k++)// skip the "h" and load the first 2 characters after that into buffer
{
parse_test++;
deg_buffer[k] = *parse_test;
}
B_GPS_lat_deg = atof(deg_buffer);// convert to float
char min_buffer[5]; // buffer for the minutes
for (int k = 0; k <= 4; k++) // copies the minutes from the parse_test to the buffer
{
parse_test++;
min_buffer[k] = *parse_test;
}
B_GPS_lat_min = atof(min_buffer); //convert to float
gps_ball_lat = B_GPS_lat_deg+(B_GPS_lat_min/60); //convert from ddmm.mm to decimal degrees dd.dddd
cout << gps_ball_lat << "\n";
return(0);
}