请教一个关于scanf函数的简单问题,会的请入
#include <stdio.h>
#include <stdlib.h>
#define MAXVERTEX 20
typedef char VertexType;
typedef int EdgeType;
typedef struct EdgeNode
{
intadjvex; //要存放的下标
EdgeType weight;
struct EdgeNode *next;
}EdgeNode;
typedef struct VertexNode
{
VertexType data;
struct EdgeNode *firstedge;
}VertexNode,AdjList;
typedef struct GraphAdjList
{
AdjList adjList;
int numVertexAdjList;
int numEdgeAdjList;
}GraphAdjList;
static int Flag;
//建造一个图
GraphAdjList* CreateAdjList(GraphAdjList *G)
{
int i = 0,j = 0;
EdgeNode *e;
VertexType c;
printf("请输入图的顶点数和边数,中间用逗号隔开:\n");
fflush(stdin);
scanf(" %d,%d",&(G->numVertexAdjList),&(G->numEdgeAdjList));
printf("请输入顶点的值 :\n");
scanf("%c",&c);
while(i < G->numVertexAdjList)
{
if(c == '\n')
break;
G->adjList.data = c;
G->adjList.firstedge = NULL;
scanf("%c",&c);
}
for(i = 0;i < G->numEdgeAdjList;i++)
{
printf("请输入边(Vi~Vj)的邻接顶点的下标:");
scanf("%d,%d",i,j);
e = (EdgeNode*)malloc(sizeof(EdgeNode));
e->adjvex = j;
e->next = G->adjList.firstedge;
G->adjList.firstedge = e;
e = (EdgeNode*)malloc(sizeof(EdgeNode));
e->adjvex = i;
e->next = G->adjList.firstedge;
G->adjList.firstedge = e;
}
return G;
}
//给标识数组赋初值0
void InitFlag()
{
int i;
for(i = 0;i < MAXVERTEX;i++)
{
Flag = 0;
}
}
void DepthFirstSearch(GraphAdjList *GL,int i)
{
int j = 0;
EdgeNode *p;
p = GL->adjList.firstedge;
Flag = 1; //赋值为1说明已经遍历过
printf("%c",GL->adjList.data);
while(p != NULL)
{
if(Flag == 0)
{
DepthFirstSearch(GL,p->adjvex);
}
p = p->next;
}
}
int main()
{
int k = 0;
GraphAdjList *G;
GraphAdjList *GL;
InitFlag();
fflush(stdin);
GL = CreateAdjList(G);
DepthFirstSearch(GL,k);
return 0;
}
请问一下 scanf(" %d,%d",&(G->numVertexAdjList),&(G->numEdgeAdjList));
这里我输入
4,5回车
为什么会报错呢?
怎么木有人······ 确认是不是全英文符号。中文,和英文,不仔细看也差不多。
页:
[1]