Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error in c code: expected identifier or '(' before '{' 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

like image 321
user1170443 Avatar asked Dec 22 '22 03:12

user1170443


1 Answers

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.

like image 144
Carl Norum Avatar answered Dec 24 '22 01:12

Carl Norum