C语言中用文件覆盖法删除文件中数据源代码

来源:百度知道 编辑:UC知道 时间:2024/06/06 02:40:58
我定义一个结构
struct works_list
{
char name[10];
char addr[20];
char age[10];
char phone[13];
char sex[10];
char gongzi[10];
char xueli[10];
char zhiwu[10];
char xuhao[10];
char beizhu[50];
};
/*添加函数*/
void new_work()
{
FILE *da;
char choice;
struct works_list f;
do
{
if((da = fopen("data.txt", "ab+")) == NULL)
{
printf("\n不能建立数据文件!!!");
exit(0);
}
printf("请输入序号:\n");
scanf("%s",f.xuhao );
printf("请输入姓名:\n");
scanf("%s",f.name );
printf("请输入住址:\n");
scanf("%s",f.addr);
printf("请输入年龄:\n");
scanf("%s",f.age);
printf("请输入性别[m为女f为男]:\n");
scanf("%s",f.sex);
printf("请输入工资:\n");
s

这样应该可以:
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include <string.h>

struct works_list
{
char name[10];
char addr[20];
char age[10];
char phone[13];
char sex[10];
char gongzi[10];
char xueli[10];
char zhiwu[10];
char xuhao[10];
char beizhu[50];
};

void menu()
{
}

/*接收多余的按键*/
void eatenter()
{
while(getchar() != '\n');
}
/*添加函数*/
void new_work()
{
FILE *da;
char choice;
struct works_list f;
if((da = fopen("data.txt", "a+")) == NULL)
{
printf("\n不能建立数据文件!!!");
exit(0);
}

do
{
printf("请输入序号:\n");
scanf("%s",f.xuhao );
eatenter();
printf("请输入姓名:\n");
scanf("%s",f.name );
eatent