Question: ```
struct student
{
int identity;
char name[MAX];
int no_assessment;
char assessmenttask[MAX];
int mark;
};

void appendbfile(char filename [MAX])
{
ofstream writeb;
char filenameb [MAX];
strcpy(filenameb,filename);
student s;

strcat(filenameb,".dat");

cout<<"--------------------------------"
    <<endl
    <<"Begin appending for binary file " 
    <<filenameb
    <<endl
    <<endl;

cout<<"Enter student id: ";
cin>>s.identity;

cout<<"Enter student name: ";
cin>>s.name;

writeb.open(strcpy(filenameb,".dat"),ios::binary);

writeb.seekp(0,ios::end);

writeb.write (reinterpret_cast <const char *>(&s), sizeof (s));

writeb.close();

}

```

I can run the programme but i cant seem to append a record to the binary file. Can someone help me take a look.

Thanks

Answer: 
The problem is in below line, you need to change

```
writeb.open(strcpy(filenameb,".dat"),ios::binary);

```

to

```
writeb.open(filenameb, ios::binary);

```

Because you have done `strcat(filenameb,".dat");` already and strcpy inside`writeb.open` copies '.dat' to filenameb which replaced the file name with '.dat'. If you look carefully file '.dat' is created in the same directory as your program which has your data.

Also as you don't necessary to call `seekp(0,ios::end);` to move file pointer to the end of the file, essentially open file with `ios::app` flag will append file to the end of the file.

```
writeb.open(filenameb, ios::binary | ios::app);
writeb.write (reinterpret_cast <const char *>(&s), sizeof (s));
writeb.close();

```

see file open mode : <http://en.cppreference.com/w/cpp/io/ios_base/openmode>
You need to pass the `ios::app` flag to the open function:

```
 writeb.open(filenameb, ios::binary | ios::app);

```