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Zzoh+qfKDqW2mvrMZXsnlWctyVx1M+Pf8jsOdVekaPX0hGH0RuTt8D61nqMc6eUz2jmavGXfWZ4fhqbm3PchiNB47JxkLVfhbzylR5UCefI3nPxsxyiONH8av5Mb4aN1oL2N9ZM4sdrduZk1bju7rzcm9wRR53ueocv5N4Rq/5XTZmZmb2c32rf2VjZmZmn8kXEjMzM3ucLyRmZmb2OF9IzMzM7HG+kJiZmdnjfCExMzOzx/lCYmZmZo/zhcTMzMwe5wuJmZmZPe5VFxL9L4NV1W5mZmbfw+MXkrOXEF9WzMzMPt/jFxL8Kp14qUC9+yt2svFmZmb2WV7x234rTC3GZCmvXGLMzMzsXV7xDUm8SGgbLxqsx9in/fnz5+87MzMzO+oVP9Sq327gdfStSeXoODMzM3veK36oNX7rwcsF+9500fA3ImZmZvu94q9sIF5M8F7rb+DLiJmZ2TVe+0OtmpZ+UzJKd9Yfce3OmOoy8vv377/vzMzM7KjHLySkl4l4sWB9dOEY9WVG61V4KfElxMzMbK/X/FDryOwychdfRMzMzK7xmm9IgBeTLKXRheToZWW0npmZmd3nFd+QgF4O+J544YjtwL4jMM6XETMzs+e95odaYxp6CdG+MxcQMzMze6dX/ZWNmZmZ/Uyv+SsbMzMz+7l8ITEzM7PH+UJiZmZmD/v16z/eeOPjqdpMdQAAAABJRU5ErkJggg==" alt="" />
解决代码及点评
/*
7. 删除worker2.rec中某个序号的职工记录,
再存入原文件中(用fread和fwrite函数)
*/
#include <stdio.h>
#include <stdlib.h> typedef struct Staff_9_7
{
int num;
char name[30];
char sex[5];
int age;
float salary; } Employee;
/*
读取员工信息
*/
void readStaInfo_7(Employee *tempEmp)
{
Employee temp;
FILE *fp = NULL;
fopen_s(&fp, "worker2.rec","rb");
if (fp)
{
int i = 0;
fread(&temp,sizeof(temp),1,fp);
while(!feof(fp))
{
tempEmp[i] = temp;
printf("num = %d,name = %s,sex = %s,age = %d,salary = %f\n",
tempEmp[i].num,tempEmp[i].name,tempEmp[i].sex,tempEmp[i].age,tempEmp[i].salary);
fread(&temp,sizeof(temp),1,fp);
tempEmp[i] = temp;
i++;
}
fclose(fp);
}
else
{
printf("open file failed!");
}
} /*
保存员工信息
*/
void saveEmpInfo97(Employee * emp,int n)
{
FILE *fp = NULL;
fopen_s(&fp, "worker2.rec","wb");
if (fp)
{
for (int i = 0; i < n; i++)
{
fwrite(&emp[i],sizeof(emp[i]),1,fp);
}
fclose(fp);
}
else
{
printf("open file failed!");
}
}
void main()
{
const int N = 11;
int num;
int index = 0;
Employee emp[N];
Employee newEmp[N - 1];
readStaInfo_7(emp);
printf("请输入要删除员工的编号:\n");
scanf_s("%d",&num);
for (int i = 0; i < N; i++)
{ if (num == emp[i].num)
{
continue;
}
else
{
newEmp[index++] = emp[i];
}
}
saveEmpInfo97(newEmp,N - 1);
readStaInfo_7(newEmp);
system("pause");
}
代码编译以及运行
由于资源上传太多,资源频道经常被锁定无法上传资源,同学们可以打开VS2013自己创建工程,步骤如下:
1)新建工程
2)选择工程
3)创建完工程如下图:
4)增加文件,右键点击项目
5)在弹出菜单里做以下选择
6)添加文件
7)拷贝代码与运行
程序运行结果
代码下载
http://download.csdn.net/detail/yincheng01/6694119
解压密码:c.itcast.cn