下面是我的代码,它一直告诉我第10行导致这个“语法错误接近意外令牌”('“但我无法弄清楚原因。我正在添加已经编写的代码但是它的部分说有一个错误不是我添加的内容的一部分。所以我很困惑为什么我收到这个错误。另外我想要一个很好的定义这个错误实际意味着什么。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "applanix_data.h"
#include "applanix_pos_out.h"
#define DEGREES2RADIANS (3.141592654 / 180.0)
int output_group_1(FILE *fp, /* This is line 10 */
FILE *fpout,
unsigned short myyear,
unsigned short mymonth,
unsigned short myday,
double time_sod,
double double_time_met)
{
struct applanix_data_group1 data1;
struct pospacsbet sbet;
if(fread(&data1,sizeof(struct applanix_data_group1),1,fp)==1)
{
sbet.gpstime = time_sod;
sbet.latitude = data1.latitude * DEGREES2RADIANS;
sbet.longitude = data1.longitude * DEGREES2RADIANS;
sbet.altitude = data1.altitude;
sbet.x_velocity = data1.eVelocity;
sbet.y_velocity = data1.nVelocity;
sbet.z_velocity = data1.dVelocity;
sbet.roll = data1.aircraftRoll * DEGREES2RADIANS;
sbet.pitch = data1.aircraftPitch * DEGREES2RADIANS;
sbet.platform_heading = data1.aircraftHeading * DEGREES2RADIANS;
sbet.wander_angle = data1.aircraftWanderAngle * DEGREES2RADIANS;
sbet.x_body_acceleration = data1.aircraftTransverseAcceleration;
sbet.y_body_acceleration = data1.aircraftLongitudinalAcceleration;
sbet.z_body_acceleration = data1.aircraftDownAcceleration;
sbet.x_body_angular_rate = data1.aircraftAngularRateAboutDownAxis;
sbet.y_body_angular_rate = data1.aircraftLongitudinalAcceleration;
sbet.z_body_angular_rate = data1.aircraftAngularRateAboutDownAxis;
if(fwrite(&sbet,sizeof(struct pospacsbet),1,fpout)!=1)
{
fprintf(stderr,"Error writing POSPAC SBET output!\n");
exit(-2);
}
sbet.latitude1 = sbet.latitude * (180/3.141592654);
sbet.longitude1 = sbet.longitude * (180/3.14592654);
sbet.day = sbet.gpstime/86400;
sbet.time = sbet.gpstime/86400;
sbet.hour1 = (sbet.time - sbet.day);
sbet.hour = sbet.hour1*24;
sbet.time = sbet.hour1*24;
sbet.minute1 = (sbet.time - sbet.hour);
sbet.minute = sbet.minute1*60;
sbet.time = sbet.minute1 * 60;
sbet.second1 = (sbet.time - sbet.minute);
sbet.second = sbet.second1*60;
printf("%12.8f, %12.8f, %6.3f, %i:%i:%4.2f\n",sbet.longitude1,sbet.latitude1,sbet.altitude,sbet.hour, sbet.minute, sbet.second);
return 0;
}
else
return -1;
}
编辑OP对问题的评论:
unix> g++ applanixraw2out.c
unix> ./applanixraw2out.c applanix_raw_20120508.bin > test.txt
./applanixraw2out.c: line 10: syntax error near unexpected token ('
答案 0 :(得分:14)
这不是编译器语法错误,而是shell错误。
您正在尝试直接执行C源代码。系统假设该文件是shell脚本。
您需要将其编译为可执行文件,然后运行可执行文件:
$ gcc applanixraw2out.c -o applanixraw2out
$ ./applanixraw2out [arguments]
在评论中,您说过您执行了以下操作:
unix> g++ applanixraw2out.c
unix> ./applanixraw2out.c applanix_raw_20120508.bin > test.txt
./applanixraw2out.c: line 10: syntax error near unexpected token ('
g++
命令用于C ++代码;您的代码是C,因此您应该使用gcc
代替。
您必须指定可执行文件的名称,该文件最常删除.c
的源文件名。如果不这样做,g++
和gcc
默认会生成名为a.out
的可执行文件(由于历史原因)。使用-o
选项覆盖该默认值。
此外,为了获得语法错误,您必须完成以下操作:
$ chmod +x applanixraw2out.c
设置不打算执行的文件的执行权限是mostly harmless,但是应该避免,因为它可能会使这样的错误更难以追踪。
答案 1 :(得分:1)
在评论中提到的starblue,检查两个包含的头文件中的代码。错误消息应该告诉您错误发生的确切位置。在错误中列出的行之前查看一行或两行,并确保语法正确。此错误几乎总是由前一行中缺少;
,(
,{
等引起的。