2012-01-26 20 views
4

プログラム簡単な概要(3体問題は):Cコードのエラー:予想される識別子または「(」の前に「{」トークン

#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機能上のエラーを取得します斧、xとyの異なる範囲でAY * /」私はそれが正しい方法で起因する外部関数を呼び出すか、作成していないにかもしれないと思う"error: expected identifier or '(' before '{' token"

を言って

+0

あなたのコメントは間違っています、 それは/ * ext関数と***ではありません*** * \ ext関数 – pezcode

+1

私の答えをdownvotingと変換していただきありがとうございます。彼は無効なコメントブロックでコードを掲示し、まったく同じ行に_syntax_エラーを報告しました。私は人々を助ける前に二度考えていますので、私はあなたのFAQの解釈を妨げません。 – pezcode

答えて

6

あなたの関数が名前を必要としています!のブロックを関数の外にあるコードはCでは無意味です。

実際には、いくつかの構文/概念上のエラーがあなたの例にあります。それをきれいにして質問を明確にしてください - あなたがそうしたときに私はより良く答えようとします。

+0

よろしくお願いいたします。 – user1170443

+0

残念ながらこのサイトを使用したことはありません。手動で4つのスペースを入れることなくコードをインデントするにはどうしたらよいですか? – user1170443

+0

@ user1170443:それをすべて選択し、WMDエディタウィジェットの '{}'ボタンを使用します。 – sarnold

5

ここで、次の例を考えてみましょう。

#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コンパイラは{identifierを期待しているためである次のエラー

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

を与えるだろう。上記のプログラムを次のように更新する必要があります。

#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 
$ 

希望します。

関連する問題