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 9102915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:29:57+00:00 2026-06-17T01:29:57+00:00

The user inputs books which I have to collect in an array. Could you

  • 0

The user inputs books which I have to collect in an array.
Could you help me understand why when I enter the second book, the first one is erisen?
I defined BOOK aux globally…

Could you help me understand why I can’t collect

#define   stop __asm nop
#include "book.h"
#include <iostream>
#include <cstdio>

using namespace std;

int counter = 0;
BOOK aux [1];

void print_catalogue()
{

}

void print_book(BOOK aBook)
{
    cout << endl;
    cout <<aBook.Autor<<", "<<aBook.Title<<", "<<aBook.Year<<", "<<aBook.PageCount<<", "<<aBook.Cost<<endl; 
}


void new_book()
{
    BOOK temp;
    system("cls");
    cin.getline (temp.Autor, 20);
    cout <<"ENTERING NEW BOOK: " << endl <<endl;
    cout <<"Input the author: ";
    cin.getline (temp.Autor, 20);
    cout  <<"Input the title: ";
    cin.getline (temp.Title, 50);
    cout  <<"Input the year of publishing: ";
    cin >>  temp.Year;
    cout  <<"Input the number of pages: ";
    cin >>  temp.PageCount;
    cout  <<"Input the cost: ";
    cin >>  temp.Cost;
    cout << endl;   

    counter++;

    BOOK * pn = new BOOK [counter];
    if (counter > 0)
    {
        memcpy(pn, aux, counter * sizeof(BOOK));    
    }
    pn[counter - 1] = temp;

    BOOK * aux = new BOOK[counter];
    memcpy(aux,pn, counter * sizeof(BOOK));

    delete[] pn;

    for (int i = 0; i < counter; i++)
    {
        print_book(aux[i]);
    }   

    system("pause");
    return;
}

void delete_books()
{

}

 void write_catalogue()
 {

 }

 void read_catalogue()
 {

 }

void menu()
{
    char command;
    do
    {       
        system("cls");

        cout << "p - Print the whole catalogue."<< endl;
        cout << "n - Input a new book." << endl;
        cout << "d - Delete existing book(s)." << endl;
        cout << "w - Write the catalogue to a file." << endl;
        cout << "r - Read the catalogue from a file." << endl;
        cout << "Input a new command: ";
        cin >> command;


        cout << endl << endl;
        switch (command) 
        {
            case 'p': print_catalogue(); break;
            case 'n': new_book(); break;
            case 'd': delete_books(); break;
            case 'w': write_catalogue(); break;
            case 'r': read_catalogue(); break;
            case 'q': return;
            default : 
                {
                    cout << "Please, enter a correct command." << endl;
                    system("pause");
                }
        }

    } while(true);
}

void main()
{
    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-17T01:29:59+00:00Added an answer on June 17, 2026 at 1:29 am

    Your global aux is a constant pointer to one BOOK – aux[0] and no more. You can not copy more than one BOOK hier.
    You redefine a local aux, with hide the global. What you put there is “leak” after the functions new_book() returned.

    Use std::string and containers, and don’t abuse pointers and global variables.

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

Sidebar

Related Questions

I have an array of user inputs ($atts) as key=>value pairs. Some of the
I have a textbox where a user inputs a number, like: 105.14 When I
I have a new batch form where user can select books from a div
Hi all I want to crate the simple app in which user inputs the
I have a model like this: class Book(models.Model): authors = models.ManyToManyField(User) # User is
I'm C++ begginer. I did this excercise from Deitel's book: Use a one-dimensional array
I have a program which let the user input som data which then get
I´m developing a Book Trading System... The user will input your Book to trading...
When validating user inputs in an application that is to be run across multiple
When a user inputs a value in a certain column then this value should

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.