【问题标题】:" expected identifier or ‘(’ before ‘[’ token" and " error: expected ‘)’ before ‘A’"“在‘​​[’标记之前的预期标识符或‘(’”和“错误:在‘A’之前的预期‘)’”
【发布时间】:2012-04-28 17:28:57
【问题描述】:

这是 C (adjacency.c) 中的 prog,它检查是否存在从节点 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: 错误:预期标识符或“[”标记之前的“(”

adjacency.c:10: 错误:在“A”之前应有“)”

adjacency.c:58: 错误:“A”之前的预期“)”

如何解决?

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

【问题讨论】:

  • 您好像忘记在文件顶部的path() 函数声明中添加;
  • void main() -- 上帝救你脱离地狱!

标签: c


【解决方案1】:

您应该将[N][N] 部分移动到声明的末尾,并在path 的前向声明之后添加一个分号。

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

您的代码的其余部分也存在不准确之处:

  • scanf("%d", &amp;sonnode;); 有多余的分号,应该是scanf("%d", &amp;sonnode);
  • else printf printf 应该是 else printf
  • 有些地方缺少分号
  • / 位于不应出现的一行的末尾
  • main 需要返回一个 int

【讨论】:

    【解决方案2】:

    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) /   
    

    【讨论】:

      【解决方案3】:

      第 10 行函数定义后缺少分号:

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

      【讨论】:

        【解决方案4】:

        下面一行的末尾缺少一个分号。

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-02-19
          相关资源
          最近更新 更多