Как удалить структуру из файла си
Нужна помощь) нужно добавить удаление и поиск определенных данных по запросу. Например есть структура поиск
bmw
Year of the car: 2019
Volume: 32
The serial number: 323-32
Amount for car: 4000 $
we
Year of the car: 32
Volume: 32
The serial number: 23
Amount for car: 23 $
я вожу bmw и мне показывает всю информацию о машине bmw. Удаления пишу bmw и удаляет все об этой машине.
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <conio.h>
struct spisok //структура
{
char name_avto[10];
char got_avto[10];
char suma[10];
char obem[10];
char serioner[10];
}
a;
void input (FILE*);
void app (FILE*);
void print (FILE*);
int main ()
{
char b;
FILE*avto;
while (1)
{
puts ("1-new bazaауаауау3 "); // меню
puts ("2-add from file");
puts ("3-view avto");
puts ("0-exit");
b=getch (); // 1 - раз
switch (b)
{
case '1': input (avto); break;
case '2': app (avto); break;
case '3': print (avto); break;
case '0': return 0;
default: puts ("bad rejim");
}
}
return 0;
}
//---------------------------------------------------------------
void input (FILE*avto)
{
char ch;
avto=fopen ("avtobaza.txt","wb");//открить файл
printf ("\nEnter information about the machine\n"); //Введіть інформацію про машуну
do
{
printf ("\nName of machines: "); //Назва машини
scanf ("%s",&a.name_avto);
printf ("Year of the car: "); //Рік машини
scanf ("%s",&a.got_avto);
printf ("Volume: "); //Об'єм
scanf ("%s",&a.obem);
printf ("The serial number: "); //Серійний номер
scanf ("%s",&a.serioner);
printf ("Amount for car: "); //Сума за авто
scanf ("%s",&a.suma);
fwrite (&a,sizeof (a),1,avto); //возврат
printf ("\nfinish? y/n"); //n - продовжує y - закінчає
ch=getch ();
} while (ch!='y');
fclose (avto);
}
//---------------------------------------------------------------
void print (FILE*avto)
{
int i;
avto=fopen ("avtobaza.txt","rb");
i=1;
fread (&a,sizeof (a),1,avto);
while (!feof (avto)) //перевірка кінця
{
printf ("\n%s",a.name_avto);
printf ("\nYear of the car: %s ",a.got_avto);
printf ("\nVolume: %s ",a.obem);
printf ("\nThe serial number: %s ",a.serioner);
printf ("\nAmount for car: %s $ ",a.suma);
printf ("\n");
fread (&a,sizeof (a),1,avto);
i++;
}
getch ();
}
//---------------------------------------------------------------
void app (FILE*avto)
{
char ch;
int i,k;
struct spisok mas[10], tmp;
avto=fopen ("avtobaza.txt","rb+");
k = 0;
while(!feof(avto))
fread(&mas[k++],sizeof(a),1,avto);
rewind (avto);
printf ("\nTo add the information\n");
do
{
printf ("\nName:");
scanf ("%s", &tmp.name_avto);
printf ("Year of the car:");
scanf ("%s",&tmp.got_avto);
printf ("Volume:");
scanf ("%s", &tmp.obem);
printf ("The serial number: ");
scanf ("%s", &tmp.serioner);
printf ("Amount for car:");
scanf ("%s", &tmp.suma);
fwrite (&tmp,sizeof (tmp),1,avto);
printf ("\nfinish? y/n");
ch=getch ();
} while (ch!='y');
for(i=0;i<k;i++)
fwrite(&mas[i],sizeof(a),1,avto);
fclose(avto);
}
//--------------------------------------------------------------