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

  • SEARCH
  • Home
  • 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 8063105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:54:37+00:00 2026-06-05T10:54:37+00:00

i have a program to list the students , it can add new one

  • 0

i have a program to list the students , it can add new one , search and even delete a student from the list by the student number, it contains a struct of student info .all of the information is on a file named REG.DAT . my problem is in the >>DELETE<< part.i want to delete a student from the list by its student number, but when i do this i lost the rest of the list up to the person that must be deleted . please help me to solve this problem .here is my code:

void _remove()
{
    int std_num = 0 , k ;
    int status = 1 , i = -1 , j = 0  ; 
    struct students read[100] ,temp;
    FILE *p ;

    p = fopen("reg.dat","rb");
    if(!p)
    {
        system("cls");
        cout << ">>>>>Register file could not be opened! call the support .<<<<<" << endl;
        _menu();
    }
    while(!feof(p))
    {
        fread(&read[i],sizeof(struct students),1,p) ;
        i++;
    }
    cout << "Enter STD NO. to delete from the list : " << endl ;
    cin >> std_num ;
    for( j = 0 ; j < i ; j++)
    {
        if(std_num == read[j].std_num)
        {
            for( k = j + 1 ; k < i ; k++)
            {
                memcpy(&read[k-1] , &read[k],sizeof (students));
            }
        }
    }
    fclose(p);

    FILE *fp;
    fp = fopen("reg.dat","wb"); 
    for( int l = 0 ; l < i - 2 ; l++)
        fwrite(&read[l], sizeof(struct students), 1 ,fp );
    fclose(fp);
    system("cls") ;
    cout << "STD with NO. " << std_num << " has been removed" << endl ; 
    _menu();
}
  • 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-05T10:54:38+00:00Added an answer on June 5, 2026 at 10:54 am

    You should not be using memcpy for overlapping memory sections. You should use instead memmov. As memmov description states:

    Move block of memory
    Copies the values of num bytes from the location pointed by source to the memory block pointed by destination. Copying takes place as if an intermediate buffer were used, allowing the destination and source to overlap.

    Also:
    – You could stop iterating over first loop using break statement after you have found your student number.

    Kind regards,
    Bo

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

Sidebar

Related Questions

I have a program which gets a list of locations from an sql db
I have a program that takes a list of names from a file and
I am creating a student list (linked list) that can add, view and edit
I have a program that needs to read data from a number of sources.
I have finished writing a program where you can enter 20 students' grades and
I have a program that exports a list of data in to a .txt
i have recently developed a list program in android in which there is an
I have a program which places structures in a linked list based on the
I have a Matlab program that generates a list x = 6.1692 8.1863 5.8092
I have a chat program that displays I list of online users. The message

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.