user-0 提问: 大哥们，我有个程序出问题了，能帮忙看下吗

回复:
user: user-1
content: 崩溃的时候在弹出的对话框按相应按钮进入调试，按Alt+7键查看Call Stack即“调用堆栈”里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处，看不懂时双击下一行，直到能看懂为止。

user: user-1
content: 在每个最后不带\n的printf后面加fflush(stdout); 在每个不想受接收缓冲区旧内容影响的scanf前面加rewind(stdin); 另外请检查scanf的返回值。

user: user-2

user: user-3
content: 未初始化的指针变量，编译器默认将未初始化的指针初始化为0xcc,而0xcc是被保护的数据区，因此程序崩溃。

user: user-4
content: 在main 函数中 pal.next = NULL; 然后把 &pal 传给了bulidstaff 在bulidstaff 中staffinfo *p = pal->next , 请问这句执行之后，p的值应该是什么，如果你看程序看不出来，那你可以通过DEBUG来查看p的值，看完之后，你就知道为什么 会出错了。

user: user-5
content: 没法找到错误

user: user-6
content: 修改如下：  #include <stdio.h> #include <stdlib.h> #include <string.h> int main(); int count = 3; int pass = 0; typedef struct staff { 	char name[10]; 	int age; 	int worktime; 	char sex[5]; 	char marrige[10];   //marriage 	int grade[5]; 	int wage; 	char tired[7]; }staff; typedef struct staffinfo { 	staff data; 	struct staffinfo *next; }staffinfo; staffinfo *a, *b; void loadstaff(staffinfo *pal) { 	FILE *fp; 	staffinfo *q; 	q = pal; 	q->next = NULL; 	fp = fopen("staff.c", "rb+"); 	if (fp == NULL) 	{ 		printf("canot open file"); 		system("cls"); 		return; 	} 	do 	{ 		a = (staffinfo *)malloc(sizeof(staffinfo)); 		if (a != NULL) 		{ 			if (1 == fread(&(a->data), sizeof(staff), 1, fp)) 			{ 				q->next = a; q = q->next; q->next = NULL; 			} 			else break;    //读到了最后 		} 	} while (a); 	//fflush(stdin);   //有什么用？ 	fclose(fp); return; } void savestaff(staffinfo *pal) { 	FILE *fp; 	staffinfo *p; 	fp = fopen("staff.c", "wb+"); 	if (fp == NULL)   //zx   NULL == fp 	{ 		printf("canot open file"); 		return; 	} 	//p = pal->next;   //不带头结点 	p = pal; 	while (p != NULL) 	{ 		if (fwrite(&p->data, sizeof(staff), 1, fp) != 1) 		{ 			printf("文件打开失败！"); 			return; 		} 		p = p->next; 	} 	fflush(stdin); 	printf("文件保存成功！！"); fclose(fp); } int command() { 	char a[20]; 	char password[] = { "宝塔镇河妖" }; 	scanf("%s", a); 	if (strcmp(a, password) == 0) 	{ 		printf("口令正确，你是合法用户"); 		system("pause"); 		pass = 1; 		return 1; 	} 	else 	{ 		printf("\t口令错误"); 		count--; 		printf("\t你还有%d次机会", count); 		system("pause"); 		if (count >0) 		{ 			fflush(stdin); 			command(); 		} 		else 		{ 			printf("你已经没有机会，程序将会退出!!"); 			system("pause"); 			main(); 		} 	} } int wagechange(staffinfo *a) { 	int increase; 	if (a->data.tired == "retired") 		increase = 50; 	else 		switch ((*a->data.grade)) 		{ 		case 1: 			increase = 20; break; 		case 2: 			increase = 40; break; 		case 3: 			increase = 60; break; 		case 4: 			increase = 80; break; 		case 5: 			increase = 100; break; 		default: 			break; 		} 	return increase; } void sreach(staffinfo *pal) { 	char name[10]; 	int worktime = 0; 	int grade = 0; 	int select = 0; 	char choose = 'y'; 	staffinfo *p; 	//p = pal->next; 	p = pal; 	printf("\t你可以根据职工的姓名，工龄，级别进行查询\n"); 	printf("\t1.按姓名查询\n"); 	printf("\t2.按工龄查询\n"); 	printf("\t3.按级别查询\n"); 	scanf("%d", &select); 	switch (select) 	{ 	case 1: 		printf("请输入你要查找的姓名\n"); 		scanf("%s", name); 		while (p != NULL) 		{ 			if (strcmp(p->data.name, name) == 0) 			{ 				printf("\t找到了，你要查找的姓名为%s的职工信息如下:", name); 				printf("姓名%s", a->data.name); 				printf("年龄%d", a->data.age); 				printf("工龄%d", a->data.worktime); 				printf("性别%s", a->data.sex); 				printf("婚姻情况%s", a->data.marrige); 				printf("级别%d", a->data.grade); 				printf("工资%d", a->data.wage); 				printf("是否在职？%s", a->data.tired); 				system("pause"); 				printf("是否继续查找？Y/N"); 				scanf("%c", &choose); 				if (choose == 'y' || choose == 'Y') 					sreach(pal); 				else 				{ 					printf("程序将返回主菜单"); 					main(); 				} 			}p = p->next; 		}fflush(stdin); 		printf("没有找到姓名为 %s的人", name); break; 	case 2: 		printf("请输入你要查找的工龄\n"); 		scanf("%d", &worktime); 		while (p != NULL) 		{ 			if (worktime == p->data.worktime) 			{ 				printf("\t找到了，你要查找的工龄为%d的职工信息如下:", worktime); 				printf("姓名%s", a->data.name); 				printf("年龄%d", a->data.age); 				printf("工龄%d", a->data.worktime); 				printf("性别%s", a->data.sex); 				printf("婚姻情况%s", a->data.marrige); 				printf("级别%d", a->data.grade); 				printf("工资%d", a->data.wage); 				printf("是否在职？%s", a->data.tired); 				system("pause"); 				printf("是否继续查找？Y/N"); 				scanf("%c", &choose); 				if (choose == 'y' || choose == 'Y') 					sreach(a); 				else 				{ 					printf("程序将返回主菜单"); 					main(); 				} 			}p = p->next; 		}fflush(stdin); printf("没有找到工龄是%d的人", worktime); break; 	case 3: 		printf("请输入你要查找的级别\n"); 		scanf("%d", &grade); 		while (p != NULL) 		{ 			if (grade == *p->data.grade) 			{ 				printf("\t找到了，你要查找的级别为%d的职工信息如下:", grade); 				printf("姓名%s", a->data.name); 				printf("年龄%d", a->data.age); 				printf("工龄%d", a->data.worktime); 				printf("性别%s", a->data.sex); 				printf("婚姻情况%s", a->data.marrige); 				printf("级别%d", a->data.grade); 				printf("工资%d", a->data.wage); 				printf("是否在职？%s", a->data.tired); 				system("pause"); 				printf("是否继续查找？Y/N"); 				scanf("%c", &choose); 				if (choose == 'y' || choose == 'Y') 					sreach(a); 				else 				{ 					printf("程序将返回主菜单"); 					main(); 				} 			}p = p->next; 		}fflush(stdin); printf("没有找到级别为%d的人", grade); break; 	default:printf("无效输入，返回中!"); system("pause"); main(); break; 	} } void bulidstaff() { 	staffinfo *head, *p, *q; 	head = p = NULL; 	printf("\t天王盖地虎\n"); 	printf("\t请输入口令，口令正确执行创建操作\n"); 	count = 3; 	char choose; 	command(); 	if (pass == 1) 	{ 		do 		{ 			q = (staffinfo *)malloc(sizeof(staffinfo)); 			if (q == NULL)return; 			//fflush(stdin);   //放到读入最近处 			printf("请输入职工的姓名"); scanf("%s", q->data.name); 			printf("请输入职工的年龄"); scanf("%d", &q->data.age); 			printf("请输入职工的工龄"); scanf("%d", &q->data.worktime); 			printf("请输入职工的性别"); scanf("%s", q->data.sex); 			printf("请输入职工的婚否"); scanf("%s", q->data.marrige); 			printf("请输入职工的级别"); scanf("%d", &q->data.grade); 			printf("请输入职工的工资"); scanf("%d", &q->data.wage); 			printf("请输入职工是否在职"); scanf("%s", q->data.tired); 			q->next = NULL; 			if (NULL == head) 			{ 				head = p = q; 			} 			else 			{ 				p->next = q; 				p = p->next; 			} 			printf("是否继续录入:y/n"); 			rewind(stdin);   //zx 			choose = getchar(); 		} while (choose == 'y' || choose == 'Y'); 	} 	savestaff(head); } void changestaff(staffinfo *pal) { 	staffinfo *p; 	//p = pal->next; 	p = pal; 	char name[20]; 	printf("请输入你要修改职工的姓名"); 	scanf("%s", name); 	for (; p != NULL && strcmp(name, p->data.name) != 0; ) 	{ 		p = (staffinfo *)malloc(sizeof(staffinfo)); 		p = p->next; 	} 	if (p = NULL) 	{ 		printf("找不到名字为%sde的人员", name); 	} 	else if (strcmp(name, p->data.name) == 0) { 		fflush(stdin); 		printf("找到了，请输入你要修改的员工的所有信息"); 		printf("请输入职工的姓名"); scanf("%s", p->data.name); 		printf("请输入职工的年龄"); scanf("%d", &p->data.age); 		printf("请输入职工的工龄"); scanf("%d", &p->data.worktime); 		printf("请输入职工的性别"); scanf("%s", p->data.sex); 		printf("请输入职工的婚否"); scanf("%s", p->data.marrige); 		printf("请输入职工的级别"); scanf("%d", &p->data.grade); 		printf("请输入职工的工资"); scanf("%d", &p->data.wage); 		printf("请输入职工是否在职"); scanf("%s", p->data.tired); 	} 	savestaff(pal); 	free(p); } void increasestaff(staffinfo *pal) { 	staffinfo *p; 	char choose; 	p = pal; 	while (p->next) p = p->next; 	do { 		p->next = malloc(sizeof(staffinfo)); 		p = p->next; 		p->next = NULL; 		printf("请输入职工的姓名"); scanf("%s", p->data.name); 		printf("请输入职工的年龄"); scanf("%d", &p->data.age); 		printf("请输入职工的工龄"); scanf("%d", &p->data.worktime); 		printf("请输入职工的性别"); scanf("%s", p->data.sex); 		printf("请输入职工的婚否"); scanf("%s", p->data.marrige); 		printf("请输入职工的级别"); scanf("%d", p->data.grade); 		printf("请输入职工的工资"); scanf("%d", p->data.wage); 		printf("请输入职工是否在职"); scanf("%s", p->data.tired); 		printf("添加成功，是否继续？y/n"); 		rewind(stdin); 		scanf("%c", &choose); 	} while (choose == 'Y' || choose == 'y'); 	savestaff(pal); } void delestaff(staffinfo *pal) { 	staffinfo *p, *q; 	char name[20]; 	char choose; 	printf("请输入你要删除职工的姓名"); 	scanf("%19s", name); 	p = pal; 	p = (staffinfo *)malloc(sizeof(staffinfo)); 	q = (staffinfo *)malloc(sizeof(staffinfo)); 	while (p != NULL) 	{ 		if (strcmp(p->data.name, name) == 0) 		{ 			if (p == pal) 			{ 				pal = p->next; 				free(p); 			} 			else 			{ 				q->next = p->next; 				free(p); 			} 			printf("删除成功，是否继续？y/n"); 			scanf("%s", &choose); 			if (choose == 'Y' || choose == 'y') 			{ 				delestaff(pal); break; 			} 			else 				main(); 		} 		else 		{ 			q = p; 			p = p->next; 		} 	} 	savestaff(pal); } int main() { 	int select = 0; 	char choose = 'y'; 	staffinfo pal; 	pal.next = NULL; 	loadstaff(&pal); 	printf("\t\t**************************************\n"); 	printf("\t*************欢迎使用本职工管理系统***************\n"); 	printf("\t1.创建职工信息              2.查询职工信息 \n"); 	printf("\t3.修改职工信息              4.添加职工信息 \n"); 	printf("\t5.删除职工信息              6.退出 \n"); 	printf("\t.*                                            *\n"); 	printf("\t.*                                            *\n"); 	printf("\t           请输入你的选择1-6        "); 	scanf("%d", &select); 	fflush(stdin); 	switch (select) 	{ 	case 1: 		//bulidstaff(&pal); 		bulidstaff(); 		system("pause"); 		main(); 		break; 	case 2: 		sreach(&pal); 		system("pause"); 		main(); 		break; 	case 3: 		changestaff(&pal); 		system("pause"); 		main(); 		break; 	case 4: 		increasestaff(&pal); 		system("pause"); 		main(); 		break; 	case 5: 		delestaff(&pal); 		system("pause"); 		main(); 		break; 	case 6: 		printf("确定要退出程序吗？y/n"); 		fflush(stdin); scanf("%c", &choose); 		if (choose == 'y' || choose == 'Y') 		{ 			printf("程序正在退出"); 			exit(0); 		} 		else if (choose == 'N' || choose == 'n') 		{ 			printf("选择的N/n,程序将会返回主菜单"); 			system("pause"); 			main(); 		} 		else 		{ 			printf("输入不合法，程序将会返回主菜单"); 			main(); 		}	break; 	default: 		printf("输入不合法，将返回主菜单"); 		system("pause"); 		system("cls"); 		main(); 		break; 	} 	return 0; }

user: user-0
content: 条是没有问题，但是在操作程序时出现了问题

user: user-0
content: 0x00CD1704 处有未经处理的异常(在 pr.exe 中):  0xC0000005:  写入位置 0x00000044 时发生访问冲突。是这个错误- -！

user: user-0
content: 不好意思，是在执行了buildstaff函数的时候，出错了，我输完职工信息之后，程序出错 0x00111704 处有未经处理的异常(在 pr.exe 中):  0xC0000005:  写入位置 0x00000044 时发生访问冲突。void bulidstaff(staffinfo *pal)(q->next=NULL)前面那句。  {  staffinfo *p = pal->next , *q;  printf("\t天王盖地虎\n");  printf("\t请输入口令，口令正确执行创建操作\n");  count = 3;  char choose;  command();  if (pass == 1)  {  do  {  q = (staffinfo *)malloc(sizeof(staffinfo));  if (q == NULL)return;  fflush(stdin);  printf("请输入职工的姓名"); scanf("%s", q->data.name);  printf("请输入职工的年龄"); scanf("%d", &q->data.age);  printf("请输入职工的工龄"); scanf("%d", &q->data.worktime);  printf("请输入职工的性别"); scanf("%s", q->data.sex);  printf("请输入职工的婚否"); scanf("%s", q->data.marrige);  printf("请输入职工的级别"); scanf("%d",&q->data.grade);  printf("请输入职工的工资"); scanf("%d", &q->data.wage);  printf("请输入职工是否在职"); scanf("%s", q->data.tired);  q->next = NULL;  p->next = q;  p = p->next;  printf("是否继续录入:y/n");  choose = getchar();  } while (choose == 'y' || choose == 'Y');  }  savestaff(pal);    }

user: user-7
content: 一上来就给一大串代码？而且有没有说明需求是什么？怎么帮你改啊？没时间去帮你做测试啊喂

user: user-3
content: 你至少要说一下哪出错了  出什么错了