Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9122435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:06:18+00:00 2026-06-17T06:06:18+00:00

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

  • 0
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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:06:19+00:00Added an answer on June 17, 2026 at 6:06 am

    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 insidewriteb.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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code struct Student { char name[48]; float grade; int marks[10,5]; char
#include<stdio.h> typedef struct student{ int id; int mark; }stud; typedef struct stud *s1; void
Code struct Student { unsigned int ID; char name[256]; int FileLocLeft; int FileLocRight; int
Here is the code: void option5 (StudentRecord student[], int n) { double gpaThreshold; char
I have a struct called student as such: struct student{ char*lastName; char*firstName; int age;
hello i have an struct like this: struct Student { string name,lettergrade; int stdnumber,*examgrades;
struct { char a; int b; } x; Why would one define a struct
I have an array of the 'struct student' in c. struct student { int
Say I have a struct defined as such struct Student { int age; int
struct pointsto_val_def { unsigned int lhs; bitmap rhs; struct pointsto_val_def *next; }; typedef struct

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.