C 代码中的错误:预期标识符或 '{' 标记之前的 '('
程序简要概述(3 体问题):
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
double ax, ay, t;
double dt;
/* other declarations including file output, N and 6 command line arguments */
...
int main(int argc, char *argv[])
{
int validinput;
...
/* input validation */
output = fopen("..", "w");
...
/* output validation */
for(i=0; i<=N; i++)
{
t = t + dt;
vx = ...
x = ...
vy = ...
y = ...
fprintf(output, "%lf %lf %lf\n", t, x, y);
}
fclose (output);
}
/* ext function to find ax, ay at different ranges of x and y */
{
declarations
if(x < 1)
{
ax = ...
}
else if(x==1)
{
ax = ...
}
...
else
{
...
}
if(y<0)
{
...
}
...
}
我在 '{ /* ext function to find ax, ay at different range of x and y */' 行上收到错误,说 "error: Expected identifier or '('在 '{' token"
我认为这可能是由于没有以正确的方式调用或创建外部函数
Program brief overview (3 body problem):
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
double ax, ay, t;
double dt;
/* other declarations including file output, N and 6 command line arguments */
...
int main(int argc, char *argv[])
{
int validinput;
...
/* input validation */
output = fopen("..", "w");
...
/* output validation */
for(i=0; i<=N; i++)
{
t = t + dt;
vx = ...
x = ...
vy = ...
y = ...
fprintf(output, "%lf %lf %lf\n", t, x, y);
}
fclose (output);
}
/* ext function to find ax, ay at different ranges of x and y */
{
declarations
if(x < 1)
{
ax = ...
}
else if(x==1)
{
ax = ...
}
...
else
{
...
}
if(y<0)
{
...
}
...
}
I get an error on the line '{ /* ext function to find ax, ay at different ranges of x and y */' saying "error: expected identifier or '(' before '{' token"
I think it may be due to not calling or creating the external function in the right way
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的函数需要一个名字!任何函数之外的代码块在 C 中都是没有意义的。
事实上,您的示例中存在一些语法/概念错误。请清理它并澄清你的问题 - 当你这样做时我会尽力回答更好。
Your function needs a name! A block of code outside any function is meaningless in C.
There are, in fact, several syntax/conceptual errors in your example. Please clean it up and clarify your question - I'll try to answer better when you've done so.
现在,我们来看下面的例子。
如果你编译上面的程序,它会给出以下错误
,这是因为 gcc 编译器需要在
{
之前有一个identifier
。所以我们需要将上面的程序更新如下,这样就可以正常工作了。
希望有帮助!
Now, lets take the following example.
If you compile the above program, it will give you the following error
That is because the gcc compiler expects an
identifier
before{
. So we need to update the above program as followsIt will work fine.
Hope it helps!