I'm making an address book for class and i'm stuck. The teacher helped with some of the code I already have. Sorry for the lack of comments. I need help with the function to add records and then save them. Thanks
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string.h>
using namespace std;
typedef char small[15];
typedef char big[30];
struct record
{
small first;
small last;
small phone;
big address;
}
record book[20];
void ReadBook(ifstream&, struct record[20], int&);
void ShowBook(ifstream&, struct record[20], int&);
void AddRecord(ifstream&, struct record[20], int&);
void SaveBook(ifstream&, struct record[20], int&);
int main()
{
int length = 0;
ifstream infile;
infile.open ("MyBook.txt");
char responce;
ReadBook(infile, book, length);
cout<<"Would you like to see your address book?\n";
cout<<"Enter Y for yes and N for no\n";
cin>>responce;
if(responce == 'y' || responce == 'Y')
{
ShowBook(infile, book, length);
}
AddRecord(infile, book, length);
SaveBook(infile, book, length);
return 0;
}
void ReadBook(ifstream&, infile, struct record[20], int& length)
{
char 1;
int i = 0;
infile.get(book[0].first, '\n');
infile.get[1];
length = 1;
while(infile)
{
i++
infile.get(book[i].first, '\n');
infile.get(1);
}
length = i;
}
void ShowBook(ifstream&, struct record[20], int& length)
{
for(int f = 0; f <= length; f++)
{
cout<<book[f].first<<endl;
}
}
void AddRecord(ifstream&, struct record[20], int& length)
{
//I'm confused how to add records
}
void SaveBook(ifstream&, struct record[20], int& length)
{
//Also how to then save them back to the function
}