這是C中的編程(adjacency.c),它檢查節點a是否存在有向圖的方式到節點b「在'A'之前的期望標識符或'('之前'['token'和'error:expected')'」
# 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’
如何解決?
更新:感謝所有的幫助。編譯。
看起來你忘了在文件頂部的'path()'函數刪除處添加';'。 – Muggen 2012-04-28 17:30:48
'void main()' - 上帝救你脫離地獄! – 2012-04-28 17:36:24