- Автор темы
- #1
Помогите пожалуйста, как организовать удаление записи из файла.
Код:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void input(void);
void output(void);
void deleting(void);
struct s {
char name[17];//Name of work
int number;//Number of shop
int pay;//Wages per month
}file_d;
FILE *f;
//main
void main() {
int n;
clrscr();
//menu
puts("Menu");
puts("1. Record");
puts("2. Review");
puts("3. Deleting");
puts("4. Exit");
scanf("%d",&n);
fflush(stdin);
switch(n) {
case 1:input();break;
case 2:output();break;
case 3:deleting();break;
case 4:break;
}//end menu
}//end main
//function input
void input(void) {
char ch;
clrscr();
if((f=fopen("file_d.dat","a+"))==NULL) {
puts("Failed to open file");
getch();
}
while (ch != 'n') {
fflush(stdin);
printf("Enter the name of the work: ");
gets(file_d.name);
printf("Enter the number of shop: ");
scanf("%i",&file_d.number);
printf("Enter the nonthly salary: ");
scanf("%i",&file_d.pay);
fwrite(&file_d,sizeof(file_d),1,f);
puts("Continue ? y(yes)/n(no)");
ch=getch();
}
clrscr();
fclose(f);
}//end function input
//start function output
void output(void) {
clrscr();
if((f=fopen("file_d.dat","r"))==NULL) {
puts("Failed to open file");
getch();
}
puts("\n|=====================================|");
puts("| Name | Number | Pay |");
puts("|=====================================|");
while(fread(&file_d,sizeof(file_d),1,f)==1) {
printf("\n| %-12s | %-10d | %-7d |",file_d.name,file_d.number,file_d.pay);
}
puts("\n|=====================================|");
getch();
fclose(f);
}
//end function ouput