user-0 提问: VC6.0中，我写的程序 无法重新生成二进制文件 把数据写入原文件

回复:
user: user-1
content: 小心字节对齐问题。 建议扔掉旧的数据文件。 加#pragma pack(1)后重新生成新的数据文件。 字节对齐问题参考这个：#include <stdio.h> #define field_offset(s,f) (int)(&(((struct s *)(0))->f)) struct AD  { int a; char b[13]; double c;}; #pragma pack(push) #pragma pack(1) struct A1  { int a; char b[13]; double c;}; #pragma pack(2) struct A2  { int a; char b[13]; double c;}; #pragma pack(4) struct A4  { int a; char b[13]; double c;}; #pragma pack(8) struct A8  { int a; char b[13]; double c;}; #pragma pack(16) struct A16 { int a; char b[13]; double c;}; #pragma pack(pop) int main() {     printf("AD.a %d\n",field_offset(AD,a));     printf("AD.b %d\n",field_offset(AD,b));     printf("AD.c %d\n",field_offset(AD,c));     printf("\n");     printf("A1.a %d\n",field_offset(A1,a));     printf("A1.b %d\n",field_offset(A1,b));     printf("A1.c %d\n",field_offset(A1,c));     printf("\n");     printf("A2.a %d\n",field_offset(A2,a));     printf("A2.b %d\n",field_offset(A2,b));     printf("A2.c %d\n",field_offset(A2,c));     printf("\n");     printf("A4.a %d\n",field_offset(A4,a));     printf("A4.b %d\n",field_offset(A4,b));     printf("A4.c %d\n",field_offset(A4,c));     printf("\n");     printf("A8.a %d\n",field_offset(A8,a));     printf("A8.b %d\n",field_offset(A8,b));     printf("A8.c %d\n",field_offset(A8,c));     printf("\n");     printf("A16.a %d\n",field_offset(A16,a));     printf("A16.b %d\n",field_offset(A16,b));     printf("A16.c %d\n",field_offset(A16,c));     printf("\n");     return 0; } //AD.a 0 //AD.b 4 //AD.c 24 // //A1.a 0 //A1.b 4 //A1.c 17 // //A2.a 0 //A2.b 4 //A2.c 18 // //A4.a 0 //A4.b 4 //A4.c 20 // //A8.a 0 //A8.b 4 //A8.c 24 // //A16.a 0 //A16.b 4 //A16.c 24 // //

user: user-0
content: 我怎么不行。。。。你怎么做到的

user: user-0
content: 哥们 我主要是revise 这个修改函数有问题  上面那个add  没有问题 你把传递给flag参数 改变了  那还能追加吗？

user: user-2
content: 没问题，可追加，可覆盖。

user: user-0
content: 兄弟....你好像没修改啊

user: user-2
content: #include<stdio.h> #include<stdlib.h> #include<string.h>  struct Employee {     char name[20]; 	char sex[5]; 	char deparment[20]; 	double pay;	 };  void Show(void);// 展示界面 void PassWord(void);//系统通过口令 void Menu(void);//系统主菜单 void ExitSystem(void);//退出系统 void SaveEmp(struct Employee[], int, int);//保存员工数据 void LoadEmp(struct Employee[], int *);//载入员工数据 void AddEmp(struct Employee[], int *);//添加员工信息 void Result(struct Employee[], int *);//浏览员工信息 void Revise(struct Employee[], int *);//修改员工信息   void LoadEmp(struct Employee emp[], int *emp_number) { 	FILE * fp; 	int i = 0; 	if((fp = fopen("emp.dat","rb"))==NULL) { 		printf("无法打开员工数据文件\n"); 		exit(0); 	} 	 	while(fread(&emp[i], sizeof(struct Employee), 1, fp) == 1){ 		i++; 	} 	 	*emp_number = i; 	fclose(fp); }   void SaveEmp(struct Employee emp[], int k, int flag) { 	FILE * fp; 	int i; 	 	if ((fp = flag ? fopen("emp.dat", "ab") : fopen("emp.dat", "wb")) == NULL) { 		printf("不能打开数据文件\n"); 		exit(0); 	} 	 	for(i=0; i<k; i++) { 		if(fwrite(&emp[i], sizeof(struct Employee), 1, fp) != 1) { 			printf("无法写入数据\n"); 			exit(0); 		} 	} 	fclose(fp);	 }   void AddEmp(struct Employee emp[], int *emp_number) { 	char ch = 'y'; //接收回车符 	system("cls"); 	system("title 添加员工"); 	printf("\n\t\t--------------------增加员工信息------------------\n"); 	printf("\n\n\t\t 请输入员工信息:\n"); 	 	LoadEmp(emp, emp_number); 	fflush(stdin); 	while ((ch=='y')||(ch=='Y')) { 		printf("\n\t\t员工的姓名："); 		scanf("%s", emp[*emp_number].name); 		printf("\n\t\t员工的性别："); 		scanf("%s", emp[*emp_number].sex); 		printf("\n\t\t员工的部门："); 		scanf("%s", emp[*emp_number].deparment); 		printf("\n\t\t员工的工资："); 		scanf("%lf", &emp[*emp_number].pay); 		fflush(stdin); 		printf("\n\t\t是否继续添加员工信息(y/n)?："); 		scanf("%c",&ch); 		fflush(stdin); 		(*emp_number)++; 	} 	SaveEmp(emp, *emp_number, 0);// 追加在数据文件末尾 	system("pause");	 }  void Result(struct Employee emp[], int *emp_number) { 	int i; 	system("cls"); 	system("title 员工信息"); 	printf("\n\t读取中...");  	LoadEmp(emp, emp_number); 	printf("\n\n\t\t员工信息：\n\n\n"); 	printf("姓名	     性别            部门          工资\n"); 	for (i = 0; i<*emp_number; i++) {		 		printf("%-20s  %-5s %-20s %-15.2f\n", emp[i].name, emp[i].sex, emp[i].deparment, emp[i].pay); 	} 	//putchar(10); 	//system("pause");	 }  void Revise(struct Employee emp[], int *emp_number) { 	int i; 	int find; 	char str[20]; 	char ch = 'y'; 	system("cls"); 	system("title 修改信息"); 	fflush(stdin); 	LoadEmp(emp, emp_number); 	printf("\n\t\t--------------------修改员工信息------------------\n"); 	while ((ch=='y')||(ch=='Y')) { 		printf("\n\n\t\t请输入员工的姓名："); 		scanf("%s", str); 		find = 0; 		 		for (i = 0; i<*emp_number; i++) { 			if (strcmp(str, emp[i].name) == 0) { 				printf("\n\n\t\t您要修改的员工信息为：\n"); 				printf("\t\t姓名        性别        部门      工资"); 				printf("\t\t%-10s  %-10s %-10s %-15.2f\n",emp[i].name,emp[i].sex,emp[i].deparment,emp[i].pay); 				find = 1; 				break; 			} 		} 		fflush(stdin); 		if(find == 1) { 			printf("\n\n\t\t请重新输入修改的员工信息为：\n"); 		 			printf("\n\t\t员工的姓名："); 			scanf("%s", emp[i].name); 			printf("\n\t\t员工的性别："); 			scanf("%s", emp[i].sex); 			printf("\n\t\t员工的部门："); 			scanf("%s", emp[i].deparment); 			printf("\n\t\t员工的工资："); 			scanf("%lf", &emp[i].pay); 		} else { 			printf("\n\t没找到该员工！\n"); 		} 		fflush(stdin); 		printf("\n\t\t是否继续修改员工信息(y/n)?："); 		scanf("%c", &ch); 		fflush(stdin); 	} 	 	SaveEmp(emp, *emp_number, 0);//重新生成数据文件 	system("pause");	 }

user: user-0
content: 嗯 rb+可以进行 读写操作  要不您能帮我修改修改？ 我怎么都改不好  进死胡同了。。。 就写  覆盖写入文件 这段  就好  谢谢了

user: user-1
content: “rb+" 和 "rb" 不是一回事！

user: user-1
content: 你不用fseek函数想实现期望的功能比较悬。

user: user-0
content: 我试了 不管用啊

user: user-0
content: # include <stdio.h> # include <stdlib.h> # include <windows.h> # include <string.h> # include <conio.h> # include <ctype.h>   struct Employee {     char name[20]; 	char sex[5]; 	char deparment[20]; 	double pay; 	 };  void Readme(void);//打开readme.txt void Show(void);// 展示界面 void PassWord(void);//系统通过口令 void Menu(void);//系统主菜单 void ExitSystem(void);//退出系统 void SaveEmp(struct Employee[],int,int);//保存员工数据 void LoadEmp(struct Employee[],int *);//载入员工数据 void AddEmp(struct Employee[],int *);//添加员工信息 void Result(struct Employee[],int *);//浏览员工信息 void Revise(struct Employee[],int *);//修改员工信息 void Delete(struct Employee[],int *);//删除员工信息 //void NewSaveEmp(struct Employee[],int);   /*void NewSaveEmp(struct Employee emp[],int * emp_number) { 	FILE * fp; 	int i = 0; 	fopen("emp.dat", "wb"); 	for(i = 0;i < * emp_number; i++) 	{ 		fwrite(&emp[i], sizeof(struct Employee), 1, fp); 		 	} 	printf("1"); 	fclose(fp); }*/  void LoadEmp(struct Employee emp[],int * emp_number) { 	FILE * fp; 	int i = 0; 	if((fp = fopen("emp.dat","rb"))==NULL) 	{ 		printf("无法打开员工数据文件\n"); 		exit(0); 	}  	while (fread(&emp[i], sizeof(struct Employee), 1, fp) == 1 && i < 50) 	{ 		i++; 	}  	* emp_number = i; 	if (feof(fp)) 	{ 		fclose(fp); 	}  }   void SaveEmp(struct Employee emp[],int k,int flag) { 	FILE * fp; 	int i;  	if ((fp = flag ? fopen("emp.dat", "ab") : fopen("emp.dat", "wb")) == NULL) 	{ 		printf("不能打开数据文件\n"); 		exit(0); 	}  	for(i = 0;i < k; i++) 	{ 		if (fwrite(&emp[i], sizeof(struct Employee), 1, fp) != 1) 		{ 			printf("无法写入数据\n"); 			exit(0); 		} 	} 	fclose(fp);  }    void Readme(void)//打开readme 创建数据文件 { 	FILE * fp; 	 	if ((fp = fopen("emp.dat","w"))==NULL) 	{ 		system ("start ./Readme.txt"); 		fclose(fp); 		system("pause"); 	} } void Show(void) { 	system("title 员工管理系统"); 	system("color 0e"); 	printf("\n\n\n"); 	printf("\t\t\t|-----------------------------------|\n"); 	printf("\t\t\t|                                   |\n"); 	printf("\t\t\t|           员工管理系统            |\n"); 	printf("\t\t\t|                                   |\n"); 	printf("\t\t\t|-----------------------------------|\n"); 	Sleep(1000); 	printf("\t\t\t|-----------------------------------|\n"); 	printf("\t\t\t|                                   |\n"); 	printf("\t\t\t|         中国华冶科工集团          |\n"); 	printf("\t\t\t|                                   |\n"); 	printf("\t\t\t|-----------------------------------|\n"); 	Sleep(1000);     printf("\t\t\t|-----------------------------------|\n"); 	printf("\t\t\t|           石家庄项目部            |\n"); 	printf("\t\t\t|-----------------------------------|\n"); 	Sleep(1000);  	system("cls"); 	Sleep(1000); 	printf("\n\n\n\n\n\n\n\n"); 	system("color 0d"); 	printf("\t\t             小猪熊   制作             \n"); 	Sleep(2000);  } void PassWord(void) { 	system("title 登陆"); 	system("cls"); 	system("color 0a"); 	int i = 0; 	char c; 	char passwd[10] = "1602"; 	char scanfwd[20]=""; 	fflush(stdin); 	for (i = 3;i >=1;i--) 	{ 		int j = 0; 		printf("\n\n\n\n\t 密码长度最大是6位！\n"); 		printf("\n\n\n\n\t 请输入密码(你还有%d次机会):", i); 		while ((c = getch()) != '\r') 		{ 			if (j < 20 && isprint(c)) // ISprint 只接收可打印的字符 			{ 				scanfwd[j++] = c;  				putchar('*'); 			}  			if (0 < j && c == '\b') //删除密码操作 			{ 				j--; 				putchar('\b'); 				putchar(' '); 				putchar('\b'); 			}  		} 		scanfwd[j] = '\0'; 		if (strcmp (passwd,scanfwd) == 0) 		{ 			system("cls"); 			system("title 欢迎页面"); 			printf("\n\n\n"); 			printf("\t\t-----------------------------------------\n"); 			printf("\t\t*                                       *\n"); 			printf("\t\t*        欢迎使用员工信息管理系统       *\n"); 			printf("\t\t*                                       *\n"); 			printf("\t\t-----------------------------------------\n\n\t\t"); 			break; 		} 		else  		{ 			system("cls"); 			printf("\n\n\n\n\t 密码错误!请重新输入!\n"); 			continue; 		} 	} 	if (i == 0) 	{ 		system("cls"); 		system("color 0c"); 		printf("\n\n\t\t\t 对不起!你无权使用该系统!\n\n\t\t"); 		Sleep(2000); 		exit(0); 	}  }  void Menu(void) { 	printf("\n\n\n\n\t\t载入中...."); 	Sleep(2000); 	system("cls"); 	system("title 主菜单"); 	printf("\n\n\n\n"); 	printf("\t\t\t|-----------------------------------|\n"); 	printf("\t\t\t|         员工信息管理系统          |\n"); 	printf("\t\t\t|-----------------------------------|\n"); 	printf("\t\t\t|         1---增加员工信息          |\n"); 	printf("\t\t\t|         2---浏览员工信息          |\n"); 	printf("\t\t\t|         3---修改员工信息          |\n"); 	printf("\t\t\t|         4---删除员工信息          |\n"); 	printf("\t\t\t|         5---【反馈留言】          |\n"); 	printf("\t\t\t|         0---【退出系统】          |\n"); 	printf("\t\t\t|-----------------------------------|\n");  }  void ExitSystem(void) { 	system("cls"); 	system("title 再见");     system("color 0c"); 	printf("\n\n\n\n\n"); 	printf("\t*****************************************************************\n"); 	printf("\t*****************************************************************\n"); 	printf("\t* *                                                           * *\n"); 	printf("\t* *                     感谢您的使用，再见!                   * *\n"); 	printf("\t* *                                                           * *\n"); 	printf("\t*****************************************************************\n"); 	printf("\t*****************************************************************\n"); 	Sleep(2000); 	exit(0); 	 }  void AddEmp(struct Employee emp[],int * emp_number) { 	system("cls"); 	system("title 添加员工"); 	printf("\n\t\t--------------------增加员工信息------------------\n"); 	printf("\n\n\t\t 请输入员工信息:\n"); 	int k = 0;//员工添加的次数 	char ch = 'y'; //接收回车符 	char c; 	LoadEmp(emp,emp_number); 	fflush(stdin); 	while ((ch=='y')||(ch=='Y')) 	{ 		printf("\n\t\t员工的姓名："); 		scanf("%s",&emp[k].name); 		printf("\n\t\t员工的性别："); 		scanf("%s",&emp[k].sex); 		printf("\n\t\t员工的部门："); 		scanf("%s",&emp[k].deparment); 		printf("\n\t\t员工的工资："); 		scanf("%lf",&emp[k].pay); 		fflush(stdin); 		printf("\n\t\t是否继续添加员工信息(y/n)?："); 		scanf("%c",&ch); 		c = getchar(); 		k++; 	} 	* emp_number += k; 	SaveEmp(emp,k,1);// 追加在数据文件末尾 	system("pause");  }  void Result(struct Employee emp[],int * emp_number) {  	system("cls"); 	system("title 员工信息"); 	printf("\n\n\n\n\t\t读取中..."); 	Sleep(2000); 	system("cls"); 	LoadEmp(emp,emp_number); 	printf("\n\n\t\t员工信息：\n\n\n"); 	printf("\t\t姓名        性别        部门      工资"); 	for (int i = 0; i < * emp_number; i++) 	{ 		 	     printf("\n\n\t\t%-10s  %-10s %-10s %-15.2f",emp[i].name,emp[i].sex,emp[i].deparment,emp[i].pay); 		 printf("\n\n"); 	} 	putchar(10); 	system("pause"); 	 }  void Revise(struct Employee emp[],int * emp_number) { 	int i; 	char str[20]; 	char c,ch = 'y'; 	system("cls"); 	system("title 修改信息"); 	fflush(stdin); 	LoadEmp(emp,emp_number); 	printf("\n\t\t--------------------修改员工信息------------------\n"); 	while ((ch=='y')||(ch=='Y')) 	{ 		printf("\n\n\t\t请输入员工的姓名："); 		scanf("%s",str); 	 		for (i = 0;i < * emp_number;i++) 		{ 			if (strcmp(str, emp[i].name) == 0) 			{ 				printf("\n\n\t\t您要修改的员工信息为：\n\n\n"); 				printf("\t\t姓名        性别        部门      工资"); 				 printf("\n\n\t\t%-10s  %-10s %-10s %-15.2f",emp[i].name,emp[i].sex,emp[i].deparment,emp[i].pay); 			} 		} 		fflush(stdin); 		printf("\n\n\t\t请重新输入修改的员工信息为：\n\n\n");  		printf("\n\t\t员工的姓名："); 		scanf("%s",&emp[i].name); 		printf("\n\t\t员工的性别："); 		scanf("%s",&emp[i].sex); 		printf("\n\t\t员工的部门："); 		scanf("%s",&emp[i].deparment); 		printf("\n\t\t员工的工资："); 		scanf("%lf",&emp[i].pay); 		fflush(stdin); 		printf("\n\t\t是否继续修改员工信息(y/n)?："); 		scanf("%c",&ch); 		c = getchar(); 	} 		 	SaveEmp(emp, * emp_number,0);//重新生成数据文件 	system("pause"); 	  } void Delete(struct Employee emp[],int * emp_number) {  }  	 int main(void) { 	struct Employee emp[50]; 	int choose,emp_number = 0; 	Readme(); 	Show(); 	PassWord(); 	Sleep(2000); 	while (1) 	{ 		system("cls"); 		Menu(); 		printf("\n\n\t\t\t请选择0~5功能菜单序号："); 		scanf("%d",&choose); 		switch (choose) 		{ 		       case 0:ExitSystem();break; 			   case 1:AddEmp(emp,&emp_number);break; 			   case 2:Result(emp,&emp_number);break; 			   case 3:Revise(emp,&emp_number);break; 			   case 4:Delete(emp,&emp_number);break; 			   case 5:system("start http://www.baidu.com/?tn=56060048_4_pg"); 		} 			  	 	}  	return 0; }

user: user-1
content: 想覆盖写入用"rb+"  The character string mode specifies the type of access requested for the file, as follows:  "r"  Opens for reading. If the file does not exist or cannot be found, the fopen call fails.  "w"  Opens an empty file for writing. If the given file exists, its contents are destroyed.  "a"  Opens for writing at the end of the file (appending) without removing the EOF marker before writing new data to the file; creates the file first if it doesn’t exist.  "r+"  Opens for both reading and writing. (The file must exist.)  "w+"  Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed.  "a+"  Opens for reading and appending; the appending operation includes the removal of the EOF marker before new data is written to the file and the EOF marker is restored after writing is complete; creates the file first if it doesn’t exist.  When a file is opened with the "a" or "a+" access type, all write operations occur at the end of the file. The file pointer can be repositioned using fseek or rewind, but is always moved back to the end of the file before any write operation is carried out. Thus, existing data cannot be overwritten.  The "a" mode does not remove the EOF marker before appending to the file. After appending has occurred, the MS-DOS TYPE command only shows data up to the original EOF marker and not any data appended to the file. The "a+" mode does remove the EOF marker before appending to the file. After appending, the MS-DOS TYPE command shows all data in the file. The "a+" mode is required for appending to a stream file that is terminated with the CTRL+Z EOF marker.  When the "r+", "w+", or "a+" access type is specified, both reading and writing are allowed (the file is said to be open for “update”). However, when you switch between reading and writing, there must be an intervening fflush, fsetpos, fseek, or rewind operation. The current position can be specified for the fsetpos or fseek operation, if desired.  In addition to the above values, the following characters can be included in mode to specify the translation mode for newline characters:  t  Open in text (translated) mode. In this mode, CTRL+Z is interpreted as an end-of-file character on input. In files opened for reading/writing with "a+", fopen checks for a CTRL+Z at the end of the file and removes it, if possible. This is done because using fseek and ftell to move within a file that ends with a CTRL+Z, may cause fseek to behave improperly near the end of the file.   Also, in text mode, carriage return–linefeed combinations are translated into single linefeeds on input, and linefeed characters are translated to carriage return–linefeed combinations on output. When a Unicode stream-I/O function operates in text mode (the default), the source or destination stream is assumed to be a sequence of multibyte characters. Therefore, the Unicode stream-input functions convert multibyte characters to wide characters (as if by a call to the mbtowc function). For the same reason, the Unicode stream-output functions convert wide characters to multibyte characters (as if by a call to the wctomb function).  b  Open in binary (untranslated) mode; translations involving carriage-return and linefeed characters are suppressed.   If t or b is not given in mode, the default translation mode is defined by the global variable _fmode. If t or b is prefixed to the argument, the function fails and returns NULL.

user: user-0
content: 您好 我可以用“ab”的方式 打开文件 并且能够添加数据进去  但是我想覆盖写入就不行了 编译能够通过 就是存储不了   我把我的所有代码 都贴上吧 我不知道为什么   # include <stdio.h> # include <stdlib.h> # include <windows.h> # include <string.h> # include <conio.h> # include <ctype.h>   struct Employee {     char name[20]; 	char sex[5]; 	char deparment[20]; 	double pay; 	 };  void Readme(void);//打开readme.txt void Show(void);// 展示界面 void PassWord(void);//系统通过口令 void Menu(void);//系统主菜单 void ExitSystem(void);//退出系统 void SaveEmp(struct Employee[],int,int);//保存员工数据 void LoadEmp(struct Employee[],int *);//载入员工数据 void AddEmp(struct Employee[],int *);//添加员工信息 void Result(struct Employee[],int *);//浏览员工信息 void Revise(struct Employee[],int *);//修改员工信息 void Delete(struct Employee[],int *);//删除员工信息 //void NewSaveEmp(struct Employee[],int);   /*void NewSaveEmp(struct Employee emp[],int * emp_number) { 	FILE * fp; 	int i = 0; 	fopen("emp.dat", "wb"); 	for(i = 0;i < * emp_number; i++) 	{ 		fwrite(&emp[i], sizeof(struct Employee), 1, fp); 		 	} 	printf("1"); 	fclose(fp); }*/  void LoadEmp(struct Employee emp[],int * emp_number) { 	FILE * fp; 	int i = 0; 	if((fp = fopen("emp.dat","rb"))==NULL) 	{ 		printf("无法打开员工数据文件\n"); 		exit(0); 	}  	while (fread(&emp[i], sizeof(struct Employee), 1, fp) == 1 && i < 50) 	{ 		i++; 	}  	* emp_number = i; 	if (feof(fp)) 	{ 		fclose(fp); 	}  }   void SaveEmp(struct Employee emp[],int k,int flag) { 	FILE * fp; 	int i;  	if ((fp = flag ? fopen("emp.dat", "ab") : fopen("emp.dat", "wb")) == NULL) 	{ 		printf("不能打开数据文件\n"); 		exit(0); 	}  	for(i = 0;i < k; i++) 	{ 		if (fwrite(&emp[i], sizeof(struct Employee), 1, fp) != 1) 		{ 			printf("无法写入数据\n"); 			exit(0); 		} 	} 	fclose(fp);  }    void Readme(void)//打开readme 创建数据文件 { 	FILE * fp; 	 	if ((fp = fopen("emp.dat","w"))==NULL) 	{ 		system ("start ./Readme.txt"); 		fclose(fp); 		system("pause"); 	} } void Show(void) { 	system("title 员工管理系统"); 	system("color 0e"); 	printf("\n\n\n"); 	printf("\t\t\t|-----------------------------------|\n"); 	printf("\t\t\t|                                   |\n"); 	printf("\t\t\t|           员工管理系统            |\n"); 	printf("\t\t\t|                                   |\n"); 	printf("\t\t\t|-----------------------------------|\n"); 	Sleep(1000); 	printf("\t\t\t|-----------------------------------|\n"); 	printf("\t\t\t|                                   |\n"); 	printf("\t\t\t|         中国华冶科工集团          |\n"); 	printf("\t\t\t|                                   |\n"); 	printf("\t\t\t|-----------------------------------|\n"); 	Sleep(1000);     printf("\t\t\t|-----------------------------------|\n"); 	printf("\t\t\t|           石家庄项目部            |\n"); 	printf("\t\t\t|-----------------------------------|\n"); 	Sleep(1000);  	system("cls"); 	Sleep(1000); 	printf("\n\n\n\n\n\n\n\n"); 	system("color 0d"); 	printf("\t\t             小猪熊   制作             \n"); 	Sleep(2000);  } void PassWord(void) { 	system("title 登陆"); 	system("cls"); 	system("color 0a"); 	int i = 0; 	char c; 	char passwd[10] = "1602"; 	char scanfwd[20]=""; 	fflush(stdin); 	for (i = 3;i >=1;i--) 	{ 		int j = 0; 		printf("\n\n\n\n\t 密码长度最大是6位！\n"); 		printf("\n\n\n\n\t 请输入密码(你还有%d次机会):", i); 		while ((c = getch()) != '\r') 		{ 			if (j < 20 && isprint(c)) // ISprint 只接收可打印的字符 			{ 				scanfwd[j++] = c;  				putchar('*'); 			}  			if (0 < j && c == '\b') //删除密码操作 			{ 				j--; 				putchar('\b'); 				putchar(' '); 				putchar('\b'); 			}  		} 		scanfwd[j] = '\0'; 		if (strcmp (passwd,scanfwd) == 0) 		{ 			system("cls"); 			system("title 欢迎页面"); 			printf("\n\n\n"); 			printf("\t\t-----------------------------------------\n"); 			printf("\t\t*                                       *\n"); 			printf("\t\t*        欢迎使用员工信息管理系统       *\n"); 			printf("\t\t*                                       *\n"); 			printf("\t\t-----------------------------------------\n\n\t\t"); 			break; 		} 		else  		{ 			system("cls"); 			printf("\n\n\n\n\t 密码错误!请重新输入!\n"); 			continue; 		} 	} 	if (i == 0) 	{ 		system("cls"); 		system("color 0c"); 		printf("\n\n\t\t\t 对不起!你无权使用该系统!\n\n\t\t"); 		Sleep(2000); 		exit(0); 	}  }  void Menu(void) { 	printf("\n\n\n\n\t\t载入中...."); 	Sleep(2000); 	system("cls"); 	system("title 主菜单"); 	printf("\n\n\n\n"); 	printf("\t\t\t|-----------------------------------|\n"); 	printf("\t\t\t|         员工信息管理系统          |\n"); 	printf("\t\t\t|-----------------------------------|\n"); 	printf("\t\t\t|         1---增加员工信息          |\n"); 	printf("\t\t\t|         2---浏览员工信息          |\n"); 	printf("\t\t\t|         3---修改员工信息          |\n"); 	printf("\t\t\t|         4---删除员工信息          |\n"); 	printf("\t\t\t|         5---【反馈留言】          |\n"); 	printf("\t\t\t|         0---【退出系统】          |\n"); 	printf("\t\t\t|-----------------------------------|\n");  }  void ExitSystem(void) { 	system("cls"); 	system("title 再见");     system("color 0c"); 	printf("\n\n\n\n\n"); 	printf("\t*****************************************************************\n"); 	printf("\t*****************************************************************\n"); 	printf("\t* *                                                           * *\n"); 	printf("\t* *                     感谢您的使用，再见!                   * *\n"); 	printf("\t* *                                                           * *\n"); 	printf("\t*****************************************************************\n"); 	printf("\t*****************************************************************\n"); 	Sleep(2000); 	exit(0); 	 }  void AddEmp(struct Employee emp[],int * emp_number) { 	system("cls"); 	system("title 添加员工"); 	printf("\n\t\t--------------------增加员工信息------------------\n"); 	printf("\n\n\t\t 请输入员工信息:\n"); 	int k = 0;//员工添加的次数 	char ch = 'y'; //接收回车符 	char c; 	LoadEmp(emp,emp_number); 	fflush(stdin); 	while ((ch=='y')||(ch=='Y')) 	{ 		printf("\n\t\t员工的姓名："); 		scanf("%s",&emp[k].name); 		printf("\n\t\t员工的性别："); 		scanf("%s",&emp[k].sex); 		printf("\n\t\t员工的部门："); 		scanf("%s",&emp[k].deparment); 		printf("\n\t\t员工的工资："); 		scanf("%lf",&emp[k].pay); 		fflush(stdin); 		printf("\n\t\t是否继续添加员工信息(y/n)?："); 		scanf("%c",&ch); 		c = getchar(); 		k++; 	} 	* emp_number += k; 	SaveEmp(emp,k,1);// 追加在数据文件末尾 	system("pause");  }  void Result(struct Employee emp[],int * emp_number) {  	system("cls"); 	system("title 员工信息"); 	printf("\n\n\n\n\t\t读取中..."); 	Sleep(2000); 	system("cls"); 	LoadEmp(emp,emp_number); 	printf("\n\n\t\t员工信息：\n\n\n"); 	printf("\t\t姓名        性别        部门      工资"); 	for (int i = 0; i < * emp_number; i++) 	{ 		 	     printf("\n\n\t\t%-10s  %-10s %-10s %-15.2f",emp[i].name,emp[i].sex,emp[i].deparment,emp[i].pay); 		 printf("\n\n"); 	} 	putchar(10); 	system("pause"); 	 }  void Revise(struct Employee emp[],int * emp_number) { 	int i; 	char str[20]; 	char c,ch = 'y'; 	system("cls"); 	system("title 修改信息"); 	fflush(stdin); 	LoadEmp(emp,emp_number); 	printf("\n\t\t--------------------修改员工信息------------------\n"); 	while ((ch=='y')||(ch=='Y')) 	{ 		printf("\n\n\t\t请输入员工的姓名："); 		scanf("%s",str); 	 		for (i = 0;i < * emp_number;i++) 		{ 			if (strcmp(str, emp[i].name) == 0) 			{ 				printf("\n\n\t\t您要修改的员工信息为：\n\n\n"); 				printf("\t\t姓名        性别        部门      工资"); 				 printf("\n\n\t\t%-10s  %-10s %-10s %-15.2f",emp[i].name,emp[i].sex,emp[i].deparment,emp[i].pay); 			} 		} 		fflush(stdin); 		printf("\n\n\t\t请重新输入修改的员工信息为：\n\n\n");  		printf("\n\t\t员工的姓名："); 		scanf("%s",&emp[i].name); 		printf("\n\t\t员工的性别："); 		scanf("%s",&emp[i].sex); 		printf("\n\t\t员工的部门："); 		scanf("%s",&emp[i].deparment); 		printf("\n\t\t员工的工资："); 		scanf("%lf",&emp[i].pay); 		fflush(stdin); 		printf("\n\t\t是否继续修改员工信息(y/n)?："); 		scanf("%c",&ch); 		c = getchar(); 	} 		 	SaveEmp(emp, * emp_number,0);//重新生成数据文件 	system("pause"); 	  } void Delete(struct Employee emp[],int * emp_number) {  }  	 int main(void) { 	struct Employee emp[50]; 	int choose,emp_number = 0; 	Readme(); 	Show(); 	PassWord(); 	Sleep(2000); 	while (1) 	{ 		system("cls"); 		Menu(); 		printf("\n\n\t\t\t请选择0~5功能菜单序号："); 		scanf("%d",&choose); 		switch (choose) 		{ 		       case 0:ExitSystem();break; 			   case 1:AddEmp(emp,&emp_number);break; 			   case 2:Result(emp,&emp_number);break; 			   case 3:Revise(emp,&emp_number);break; 			   case 4:Delete(emp,&emp_number);break; 			   case 5:system("start http://www.baidu.com/?tn=56060048_4_pg"); 		} 			  	 	}  	return 0; }

user: user-1
content: 在cmd窗口中输入以下命令运行程序 cd /d "exe程序所在盘符和全路径" "exe程序名"  或者VS IDE中 VC6：  工程、设置、Debug、工作目录：填写emp.dat所在目录。 VS20XX：  项目、属性、配置属性、调试、工作目录：填写emp.dat所在目录。 再按F5运行。

user: user-1
content: #pragma pack(push,1) struct Employee {     char name[20];     char sex[5];     char deparment[20];     double pay;       }; #pragma pack(pop)  推荐使用WinHex软件查看硬盘或文件或内存中的原始字节内容。

user: user-0
content: 我截取了部分代码   无法重新生成文件  也没有办法存储   求大神 指点  谢谢