c程序 中有一个警告 哪位帮我改一下 谢谢

来源:百度知道 编辑:UC知道 时间:2024/05/16 07:59:32
#include<stdio.h>
#define MAXV 100
#define MAX 1000
typedef struct {char vexs[MAXV];
int edges[MAXV][MAXV];
int n,e;}MGraph;

void main()
{
MGraph *initializemgr(MGraph *f);
void dijkstra(MGraph *h,int k1,int k2);
int i,j,s1,t1;
char s,t;
MGraph *g; MGraph *q;
g=initializemgr(q); /*警告 wuyong.c 15: 可能在'q'定义以前使用了它在 main 函数中*/
printf("Please input the starting point(betwin a,b,c and d):");
while(1)
{ scanf("%c",&s);
if(s=='a'||s=='b'||s=='c'||s=='d')break;
else
printf("\nError!Please input again :");
}
while(1)
{i=0;
if(g->vexs[i]==s){s1=i;break;}
else i++;
}
printf("\n") ;
printf("Please input the destination (betwin a,b,c and d):");
while(1)
{ scanf("%c",&t);
if(t=='a'||t=='b

while(1)
{j=0;
if(g->vexs[j]==t){t1=j;break;}
else j++;
}

这是很很明显的死循环,嗯。。。
每次循环开始j都被赋值为0;如果g->vexs[0]!=t,那么就是死循环。
j=0应该放在循环体外面,这样:

j=0;
while(1)
{if(g->vexs[j]==t){t1=j;break;}
else j++;
}

除了楼上的错误,此程序的第四十二行应该为getchar();

能不能实现 起点--> -->终点 这个样子??
因为我那个是 反过来的。 ???