user-0 提问: 用scanf函数输入值越界

回复:
user: user-0
content: 在调试的时候又发现了一个问题，就是下一步如果多个方向都可以走的话怎么选的问题。 程序里 MarkMap(map, position, location);   //标记可以通过的位置 			e.passnum = location; 			e.location = position; 			e.direction = 0;                    //向东探索 			Push(S, e); 是直接向右探索的，假设迷宫的出入口分布为（1，1）、（8，8） 探索方向应该是向右下方进行的，如何能让下一步探索综合向右和向下的结果呢

user: user-1
content: 你输入数据"1，1 "时，是不是汉字下的逗号啊？？？

user: user-0
content: 之前是因为输入了汉子的逗号 谢谢各位大侠

user: user-2
content: 你用空格分开，输入时也是用空格

user: user-1
content: 上面的回复：不是汉字逗号

user: user-1
content: 没问题啊，只要你输入的不是汉字括号，scanf我这里运行可以通过的。没有异常。赋值也是正确。

user: user-3
content: 输入的时候，两个数字用英文下的逗号分隔

user: user-0
content: 好的 蟹蟹大侠！ #include<stdio.h> #include<string.h> #include<malloc.h> #include<stdlib.h>  #define ERR_NOMEMRROY -1  #define ERR_INVALIDPARAM -2 #define ERR_OVERFLOW -3 #define ERR_ILLEGALINDEX -4 #define ERR_EMPTYRESULT -5  #define MAZE_MAXSIZE 100     //迷宫最大行数和列数  typedef struct{ 	int x; 	int y; }position;                //记录迷宫的行和列  typedef struct { 	int passnum;          //路径块的序号 	position location;    //路径块在迷宫中的位置	 	int direction;		 //从当前路径走向下一路径块的方向 0东1西2南3北 }datatype;  typedef struct node { 	datatype data; 	struct node* next;	 }StackNode,*LinkStack;  int InitStack(LinkStack *top) { 	StackNode *t = NULL;   	if (!top)return ERR_INVALIDPARAM;  	//分配内存空间 	t = (StackNode*)malloc(sizeof(StackNode)); 	if (!t)return ERR_NOMEMRROY;  	t->next = NULL; 	(*top) = t; 	return 0; }  int Push(LinkStack top, datatype e) { 	StackNode *p = NULL; 	if (!top)return ERR_INVALIDPARAM;  	p = (StackNode*)malloc(sizeof(StackNode)); 	if (!p)return ERR_NOMEMRROY; 	 	p->data = e; 	p->next = top->next; 	top->next = p; 	return 0; }  int Pop(LinkStack top, datatype *e) { 	StackNode *p = NULL; 	if (!p)return ERR_INVALIDPARAM; 	if (!p->next)return ERR_EMPTYRESULT;  	p = top->next; 	top->next = p->next; 	*e = p->data; 	free(p); 	return 0; } int DestoryStack(LinkStack top) { 	StackNode *p = NULL; 	if (!top) return ERR_INVALIDPARAM;  	while (top) 	{ 		p = top; 		top = top->next; 		free(p); 	} 	return 0; } int StackEmpty(LinkStack top) { 	if (!top)return ERR_INVALIDPARAM; 	return(top->next == NULL); }  int Peek(LinkStack top, datatype *e) { 	if (!top)return ERR_INVALIDPARAM; 	if (!top->next)return ERR_EMPTYRESULT; 	 	*e = top->next->data; 	return 0; }  int CanPass(int map[][MAZE_MAXSIZE], position pos) //0表示可以以通过 { 	return (map[pos.x][pos.y] == 0); }  int MarkMap(int map[][MAZE_MAXSIZE], position pos, int mark) //用mark标记迷宫中的pos位置 { 	map[pos.x][pos.y] = mark; 	return 0; } int NextPos(int map[][MAZE_MAXSIZE], int dir, position *pos) //根据当前位置及移动方向，求得下一方向 为什么要用*pos { 	position d[4] = { {0,1},{1,0},{0,-1},{-1,0} }; 	(*pos).x += d[dir].x; 	(*pos).y += d[dir].y; 	return 0;  } /*计算迷宫入口到出口的路径*/ int MazePath(int map[][MAZE_MAXSIZE], position entry, position exit) { 	int location = 1; 	position position = entry; 	datatype e; 	//初始化链栈 	LinkStack S; 	InitStack(&S);  	do 	{ 		if (CanPass(map, position)) 		{ 			MarkMap(map, position, location);   //标记可以通过的位置 			e.passnum = location; 			e.location = position; 			e.direction = 0;                    //向东探索 			Push(S, e);  			if (position.x == exit.x&&position.y == exit.y) 				return location;  			location++; 			NextPos(map, e.direction, &position); 		} 		else  //当前位置不能通过  		{ 			if (!StackEmpty(S)) 			{ 				Pop(S, &e); 				location--;  				 				if (e.direction<3) 				{ 					e.direction++;   //寻找方向 					Push(S, e);		//入栈该位置的下一个方向 					location++;		 					position = e.location; //确定当前位置 					NextPos(map, e.direction, &position);//确定下一个位置  				} 				while (e.direction == 3 && !StackEmpty(S))  //direction=3说明四个方向都走不通，退回到上一步 				{ 					MarkMap(map, e.location, 0);  //标记位置不通 					Pop(S,&e); 					location--; 				} 			}	 		} 	} while (!StackEmpty(S)); 	DestoryStack(S); 	return 0; }  void PrintMaze(int map[][MAZE_MAXSIZE], int row, int col) { 	int i, j;  	//打印列号 	printf("\n   "); 	for (i = 0; i < row; i++) 		printf("%3d",i); 	printf("\n");  	//打印行号 	for (i = 0; i < row; i++) 	{ 		printf("%3d", i); 		for (j = 0; j < col; j++) 		{ 			if (map[i][j] == 0)printf("   ");  //非障碍物打印空格 			else if (map[i][j] == 1)printf("  #");     //障碍物打印# 			else printf("%3d", map[i][j]); 		} 		printf("\n"); 	} 	printf("\n"); }  int main() { 	int steps = 0; 	position entry, exit; 	int maze[MAZE_MAXSIZE][MAZE_MAXSIZE] = { 	{ 1,1,1,1,1,1,1,1,1,1 }, 	{ 1,0,0,1,0,0,0,1,0,1 }, 	{ 1,0,0,1,0,1,0,1,0,1 }, 	{ 1,0,0,0,0,1,1,0,0,1 }, 	{ 1,0,1,1,1,0,0,0,1,1 }, 	{ 1,0,0,0,1,0,0,0,0,1 }, 	{ 1,0,1,0,0,0,1,0,0,1 }, 	{ 1,0,1,1,1,0,1,1,0,1 }, 	{ 1,1,0,0,0,0,0,0,0,1 }, 	{ 1,1,1,1,1,1,1,1,1,1 }, 	};  	printf("迷宫的结构如下：\n"); 	PrintMaze(maze, 10, 10);  	printf("请输入入口的行和列（row,col）："); 	scanf_s("%d,%d", &entry.x, &entry.y);  	printf("%d,%d", entry.x, entry.y); 	system("pause");  	printf("请输入出口的行和列（row,col）："); 	scanf_s("%d,%d", &exit.x, &exit.y);  	steps = MazePath(maze, entry, exit); 	if (steps == 0)printf("迷宫没有从入口到出口的路径\n"); 	else printf("从入口到出口需要%2d步\n", steps);  	PrintMaze(maze, 10, 10);  	getch(); 	return 0;   }

user: user-1
content: 把完整代码贴上来，我给你调试

user: user-0
content: 不是的，我试过不加逗号了，而且scanf里也写逗号了