简体   繁体   中英

syntax error before 'for'

i got error: "syntax error before 'for'" and I just don't understand why? Could you please explain why is that? I have few similar errors in code.

#define N 1024

 void Reverse_Binary( double *a, unsigned long Len);

int main()
   // here is error as well: error: syntax error before '{' token
{
 //here are different variables for all code

 buf = malloc(num_items*sizeof(double));

 //here are different functions

 Reverse_Binary(buf,N); 
}

void Reverse_Binary( double *a,unsigned long Len)  
{
    long x, xprim;
    int temp;

    for (x=0; x<Len; x++)
    {
         xprim= rev(x,N);   

         if (xprim > x)
         {
             temp = a[x];
             a[x] = a[xprim];
             a[xprim] = temp;s
         }
     }  
}

You missed the main closing bracket.

Put a bracket after:

Reverse_Binary(buf,N);

} //that's the missing bracket

Also remove the last bracket after Reverse_Binary function.

Check matching brackets first. When brackets go missing, compiler messages go seemingly awok because the code snippet looks right.

It looks OK, so the only idea I have that you have maybe invisible CR characters. Some compilers on Unix/Linux do not like files edited on Windows/DOS which contains CR/LF (0x0d, 0x0a) instead of LF (0x0a) as line delimiters. Try editing your file with vi and it may show the supplemental CR as ^M characters at the end of the line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM