まず、これはクラス用なので、できることとできないことに制限があります。さらに、私は c++ とプログラミング全般に非常に慣れていないため、コードはおそらく少しがらくたです。
最初の for ループ内で cout 行の最初のセットを使用して item_list を表示すると、個々のアイテムが本来あるべき状態で表示される理由を理解しようとしています (スカイリムの成分とその効果のリスト)。
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;*/
};