c - "expected identifier or ‘(’ 之前 ‘[’ token "and "错误 : expected ‘)’ before ‘A’ "

标签 c

这是 C (adjacency.c) 中的程序,它检查是否存在从节点 a 到节点 b 的有向图方式

# 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: error: expected identifier or ‘(’ before ‘[’ token

adjacency.c:10: error: expected ‘)’ before ‘A’

adjacency.c:58: error: expected ‘)’ before ‘A’

如何修复?

更新:感谢大家的帮助。编译。

最佳答案

应该把[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 / 在一行的末尾不应该出现
  • main 需要返回一个 int

关于c - "expected identifier or ‘(’ 之前 ‘[’ token "and "错误 : expected ‘)’ before ‘A’ ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10365859/

相关文章:

C : Can you inherit a class in one extension from another separate extension? 中的 PHP 扩展

c - 在C中是否需要对char指针地址进行初始化?

c - 监视文件更改的可移植方式

python - 我可以使用 doxygen 来记录命令行程序吗?

c - 如何找到调用 malloc() 分配了多少空间?

c - 将 FILE 指针传递给函数

c - 如何检查输入结束? C、找到42

c# - 将 C 结构移植到 C#

C,帮助我理解这个 ASCII 问题

c - 是否要求从堆栈分配一个 C 可变长度数组?