Hey!
Im working on a movie list, but i donīt get the delete part of it to work.
Help please :p
Many thanks//SoulHack
# include <iostream.h>
# include <conio.h>
# include <string.h>
# include <fstream.h>
# include <stdlib.h>
# include <iomanip.h>
# include <time.h>
#include <vector>
struct film
{
char typ[30];
char titel[30];
};
void meny();
void laggtill(film &b);
void read();
void soka();
void remove();
int main()
{
int svar;
film f;
while(svar!=5)
{
meny();
cin>>svar;
cout<<endl;
cin.ignore(10,'\n');
if (svar==5)
{
system("cls");
cout<<endl<<"**** V\x84lkommen tillbaka n\x84sta g\x86ng! ****"<<endl;
getch();
}
else if (svar==1)
{
ofstream utfil;
utfil.open("filmlista", ios::app);
laggtill(f);
utfil.write((char *)&f, sizeof(film));
utfil.close();
}
else if (svar==2)
{
read();
}
else if (svar==3)
{
soka();
}
else if (svar==4)
{
remove();
}
}
return 0;
}
void meny()
{
{
tm tidstrukt;
long tidsrymd=time(NULL);
tidstrukt=*localtime(&tidsrymd);
cout<<endl;
cout<<"Dagens datum : ";
cout<<setfill('0')<<(tidstrukt.tm_year+1900)<<"-";
cout<<setw(2)<<(tidstrukt.tm_mon+1)<<"-";
cout<<setw(2)<<(tidstrukt.tm_mday)<<"";
cout<<endl;
}
cout<<endl;
cout<<"********* Meny *********"<<endl;
cout<<"* *";
cout<<endl;
cout<<"* ";
cout<<"1. L\x84gg till film"<<" *"<<endl;
cout<<"* ";
cout<<"2. Lista alla filmer"<<" *"<<endl;
cout<<"* ";
cout<<"3. S\x94k titel"<<" *"<<endl;
cout<<"* ";
cout<<"4. Ta bort film "<<" *"<<endl;
cout<<"* ";
cout<<"5. Avsluta "<<" *"<<endl;
cout<<"* *";
cout<<endl;
cout<<"************************"<<endl;
cout<<endl;
cout<<"Ange val : ";
}
void remove()
{
system("cls");
int hittad=0;
ifstream infil;
char svar[40];
film b;
cout<<"Ange filmens titel eller typ : ";
cin.getline(svar,40);
infil.open("filmlista",ios::binary);
while (infil.read((char *)&b, sizeof(film)))
{
if (stricmp(svar, b.titel)==0||(stricmp(svar, b.typ)==0))
{
//How do i do this? If i want to remove
the movie that the program finds?
}
}
{
if(hittad==0)
{
cout<<endl<<"Filmen finns ej!"<<endl;
}
}
}
void laggtill(film& b)
{
cout<<"Ange filmens titel : ";
cin.getline(b.titel, 30);
cout<<"Ange typ av film : ";
cin.getline(b.typ, 30);
system("cls");
}
void read()
{
int i=0;
ifstream infil;
film b;
infil.open("filmlista",ios::binary);
while (infil.read((char *)&b, sizeof(film)))
{
cout<<endl<<++i<<"."<<" "<<b.titel<<" "<<endl<<endl<<" "<<""<<b.typ<<""<<endl<<"________________________" <<endl;
}
infil.close();
getch();
system("cls");
}
void soka()
{
system("cls");
int hittad=0;
ifstream infil;
char svar[40];
film b;
cout<<"Ange filmens titel eller typ : ";
cin.getline(svar,40);
infil.open("filmlista",ios::binary);
while (infil.read((char *)&b, sizeof(film)))
{
if (stricmp(svar, b.titel)==0||(stricmp(svar, b.typ)==0))
{
cout<<endl<<b.titel<<" "<<"["<<b.typ<<"]"<<endl;
hittad=1;
}
}
{
if(hittad==0)
{
cout<<endl<<"Filmen finns ej!"<<endl;
}
}
}