2

これは、ノード a からノード b への有向グラフの方法で存在するかどうかをチェックする C (adjacency.c) のプログラムです。

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

#define N 11
#define FALSE 0
#define TRUE 1

typedef  int[N][N] adj_mat;

int path (adj_mat A, int u, int v)





    
void main()
    {
        adj_mat Matrix; 
        int dadnode, sonnode; 

        printf("bla-bla-bla enter nodes.\n");            
             printf("Press Ctrl+Z after finishing  of bla-bla-bla all the nodes\n");
        
        do {    
            printf("Enter the  number of first node\n"); 
            scanf("%d", &dadnode);
            printf("Enter the  number of second node\n");
            scanf("%d", &sonnode;);

            if ((dadnode < sonnode) && (sonnode <= N) && (dadnode > 0)) 
                Matrix[dadnode][sonnode] = 1; 
            } while ( (dadnode != EOF ) && (sonnode != EOF)); 


        printf("Now enter u and v nodes to check if exists way from u node to we node\n")
                        
            printf("Enter the  number of u node\n"); 
            scanf("%d", &dadnode);
            printf("Enter the  number of v node\n");
            scanf("%d", &sonnode;);

            if ((dadnode < sonnode) && (sonnode <= N) && (dadnode > 0)) 
             {
                if(path(Matrix,dadnode,sonnode) == TRUE ) 
                    printf ("Exists way from node u to node v ");   
             }
             
                else printf printf ("Not exists way from node u to node v ");   

    }






int path (adj_mat A, int u, int v) 
    {
        if (v >= u)  
        return FALSE; 

        int nodenum; 

        for(nodenum = v - 1; nodenum > 0; nodenum-- ) 
                                                          
            {
                if (A[nodenum][v] == TRUE) 
                {
                    if (nodenum == u) /
                        return TRUE;

                    else if (path (adj_mat A, int u, int nodenum)) 
                                                
                                
                        return TRUE;
                }
            }   
            
        return FALSE; 
    }

コマンドを入力すると

gcc -o adjacency -ansi adjacency.c

私は得る

adjacency.c:8: エラー: 識別子または '[' トークンの前に '(' が必要です

adjacency.c:10: エラー: 'A' の前に ')' が必要です</p>

adjacency.c:58: エラー: 'A' の前に ')' が必要です</p>

直し方 ?

更新: 助けてくれてありがとう。編集済み。

4

4 に答える 4

9

その部分を宣言の最後に移動し[N][N]、 の前方宣言の後にセミコロンを追加する必要がありpathます。

typedef  int adj_mat[N][N];
int path (adj_mat A, int u, int v);

コードの残りの部分にも不正確さがあります。

  • scanf("%d", &sonnode;);余分なセミコロンがあります。scanf("%d", &sonnode);
  • else printf printfする必要がありますelse printf
  • セミコロンがいくつかの場所で欠落しています
  • a/は、あるべきではない 1 行の末尾にあります
  • mainを返す必要がありますint
于 2012-04-28T17:31:19.533 に答える
4

int[N][N]が有効な C++ ではありません。試す:

typedef  int adj_mat[N][N];

代わりは。

また:

;行末にはセミコロン (' ') が必要です。

int path (adj_mat A, int u, int v) 
printf("Now enter u and v nodes to check if exists way from u node to we node\n")

最初のセミコロンは必要ありません

scanf("%d", &sonnode;);

余分な(余分な)printfがあります

else printf printf ("Not exists way from node u to node v "); 

無効な行があります

if (nodenum == u) /   
于 2012-04-28T17:32:19.873 に答える
1

10 行目の関数定義の後にセミコロンがありません。

int path (adj_mat A, int u, int v);
于 2012-04-28T17:31:56.240 に答える
1

下の行の最後にセミコロンがありません。

int path (adj_mat A, int u, int v);
于 2012-04-28T17:32:56.620 に答える