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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:52:49+00:00 2026-06-04T02:52:49+00:00

Firstly, this is for a class so there are limitations on what we can

  • 0

Firstly, this is for a class so there are limitations on what we can and can’t do, plus I am extremely new to c++ and programming in general, so that is why the code is probably a little crap.

I am at my wits end trying to understand why when I display the item_list using the first set of cout lines within the first for loop, it displays each individual item as it should be (its a list of skyrim ingredients and their effects).

However, when the second for loop executes, the item_list is filled with nothing but the last item that should have been inserted (wisp wrappings and their effects).

Even just pointing me in the right direction would be GREATLY appreciated 🙂

cheers

int client::fill_list(int size_in, int h1size, int h2size)
{
    char temp[ASIZE] = {'\0'};
    int j = 0;
    ifstream ifile;
    ifile.open("test.txt");

    if(ifile.is_open())
    {
        for(int i = 0; i < size_in; ++i)
        {    
            if(ifile.good())
            {       
                j = 0;
                do
                {                   
                    temp[j] = char(ifile.get());
                    ++j;
                }while(ifile.peek() != '*');
                temp[j] = char(ifile.get());
                copy(client_item.name, temp, j);
            }


            if(ifile.good())
            {
                j = 0;
                do
                {                   
                    temp[j] = char(ifile.get());
                    ++j;
                }while(ifile.peek() != '*');
                temp[j] = char(ifile.get());
                copy(client_item.effect1, temp, j);
            }

            if(ifile.good())
            {
                j = 0;
                do
                {                   
                    temp[j] = char(ifile.get());
                    ++j;
                }while(ifile.peek() != '*');
                temp[j] = char(ifile.get());
                copy(client_item.effect2, temp, j);
            }

            if(ifile.good())
            {
                j = 0;
                do
                {                   
                    temp[j] = char(ifile.get());
                    ++j;
                }while(ifile.peek() != '*');
                temp[j] = char(ifile.get());
                copy(client_item.effect3, temp, j);
            }

            if(ifile.good())
            {
                j = 0;
                do
                {                   
                    temp[j] = char(ifile.get());
                    ++j;
                }while(ifile.peek() != '*');
                temp[j] = char(ifile.get());
                copy(client_item.effect4, temp, j);
            }
            reference.into_list(i,client_item);
        cout << reference.item_list[i].name;
        cout << reference.item_list[i].effect1;
        cout << reference.item_list[i].effect2;
        cout << reference.item_list[i].effect3;
        cout << reference.item_list[i].effect4;
        getchar();
        }
    }
    for(int k = 0; k < SIZE; ++k)
    {
        cout << reference.item_list[k].name;
        cout << reference.item_list[k].effect1;
        cout << reference.item_list[k].effect2;
        cout << reference.item_list[k].effect3;
        cout << reference.item_list[k].effect4;
    }
    getchar();
    return 0;
}

…

int table::into_list(int index, item&item_in)
{
    if(index < SIZE)
    {
        item_list[index] = item_in;
        return 0;
    }
    else
        return 1;
}

…
Header for the table class

#include "hash.h"

class table
{
public:
    table()
    {
        item_list = new item [SIZE];
    }
    ~table();
    int fill(item*);
    int insert(item&, nHash&);
    int insert(item&, eHash&, int);
    int retrieve(char*,item*,int);
    int remove(int,item&);
    int remove(int);
    int check_hash(int,int,int);
    int keygen(char*, int);
    int from_list(int, item&);
    int into_list(int, item&);

//private:
    item * item_list;
    nHash name_table;
    eHash ef1_table;
    eHash ef2_table;
    eHash ef3_table;
    eHash ef4_table;
};

….
Beginning of main

#include "client.h"

int main()
{
    client program;

    program.fill_list(SIZE,HNSIZE,HESIZE);

    for(int i = 0; i < SIZE; ++i)
    {
        cout << program.reference.item_list[i].name;
        cout << program.reference.item_list[i].effect1 << endl;
        cout << program.reference.item_list[i].effect2 << endl;
        cout << program.reference.item_list[i].effect3 << endl;
        cout << program.reference.item_list[i].effect4 << endl;
    }

….

item header

#include <iostream>
#include <fstream>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

const int ASIZE = 30;
const int SIZE = 92;
const int HNSIZE = 41;
const int HESIZE = 17;

struct item
{
    item();
    ~item();
    char * name;
    char * effect1;
    char * effect2;
    char * effect3;
    char * effect4;
    int count;
    //int keygen(int,int);
    /*int name_key;
    int ef1_key;
    int ef2_key;
    int ef3_key;
    int ef4_key;*/
};
  • 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-04T02:52:50+00:00Added an answer on June 4, 2026 at 2:52 am

    It’s possible that part of the problem is how you make copies of client_item here:

    reference.into_list(i,client_item);
    

    This just assigns client_item to item_list like so:

    item_list[index] = item_in;
    

    …but since item is defined like this:

    struct item
    {
        item();
        ~item();
        char * name;
        char * effect1;
        ...
    

    …all of the items in item_list will have pointers (like name, etc.) that point to the same memory as the memory in client_item.

    For example, after each assignment, the pointers item_list[index].name and item_in.name will have the same value. (You can check that by printing both pointers, if you’re curious.) Since they both point to the same memory, if you change what’s stored at that memory, both objects will appear to change at the same time.

    That means that subsequent changes to client_item — like copying a new string into one of the places that it points — will affect all of the saved items as well.

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

Sidebar

Related Questions

Firstly I am new to android and Java so this is a beginners question.
Firstly sorry for the long piece of code pasted below. This is my first
I am in the process of writing a class that will probably end up
This is probably a noob question that I will get slated for but here
Ok, firstly I have the following code working.. although my question is this; should
There are a couple of things about Objective-C that are confusing to me: Firstly,
As I am new to all this Java EE ocean, there is so much
I'am doing homework. Firstly, there was a task to make calculator, which can evaluate
Firstly, this is just an Object Oriented Programming question and does not apply to
Firstly, this seems like something that should have been asked before, but I cannot

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.