C 代码中的错误:预期标识符或 '{' 标记之前的 '('

发布于 2024-12-29 04:36:09 字数 963 浏览 0 评论 0原文

程序简要概述(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

怎樣才叫好 2025-01-05 04:36:09

你的函数需要一个名字!任何函数之外的代码块在 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.

梦里梦着梦中梦 2025-01-05 04:36:09

现在,我们来看下面的例子。

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("hello world \n");
    return 0;
}

{
    printf("do you see this?!\n");
}

如果你编译上面的程序,它会给出以下错误

$ gcc q.c 
q.c:10:1: error: expected identifier or ‘(’ before ‘{’ token
$ 

,这是因为 gcc 编译器需要在 { 之前有一个 identifier。所以我们需要将上面的程序更新如下,这样

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("hello world \n");
    return 0;
}

void function()
{
    printf("do you see this?!\n");
    return;
}

就可以正常工作了。

$ gcc q.c 
$ ./a.out 
hello world 
$ 

希望有帮助!

Now, lets take the following example.

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("hello world \n");
    return 0;
}

{
    printf("do you see this?!\n");
}

If you compile the above program, it will give you the following error

$ gcc q.c 
q.c:10:1: error: expected identifier or ‘(’ before ‘{’ token
$ 

That is because the gcc compiler expects an identifier before {. So we need to update the above program as follows

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("hello world \n");
    return 0;
}

void function()
{
    printf("do you see this?!\n");
    return;
}

It will work fine.

$ gcc q.c 
$ ./a.out 
hello world 
$ 

Hope it helps!

月竹挽风 2025-01-05 04:36:09
include<stdio.h>
int main() {
  
  float vayasu= 18;
  printf("eppudu naa age %d\n",vayasu);
  
  vayasu =100;
  printf("mari eppudu naa age %d", vayasu);
  
  return 0;
}
include<stdio.h>
int main() {
  
  float vayasu= 18;
  printf("eppudu naa age %d\n",vayasu);
  
  vayasu =100;
  printf("mari eppudu naa age %d", vayasu);
  
  return 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文