Testthis=&*Look_in;
割り当てブレークをデバッグするときに、機能ヘッダーの最後のパラメータをchar Findthis[64]
からchar * Findthis
に変更しました。 Look_inにはメモリアドレスとメンバ値がありますが、Testthisにはそのポインタ位置が割り当てられていません。なぜこうなった?なぜ機能ヘッダーを変更すると、ポインタ割り当てが機能しなくなるのですか?
struct Node * ProbableMatch(struct Node * Look_in, int MaxNodes,
char Findthis[64])
{
char Findit[64];
strcpy_s(Findit,64,Findthis);
struct Node * CurrentHighProb;
CurrentHighProb=new(Node);
struct Node * Testthis;
Testthis=new(Node);
Testthis=&*Look_in;
while((Testthis) || (i!=(ccounter-1)))
{ //This Testthis does not cause exception
string str1;
string str2;
n1=sizeof(Testthis->NAME);
n2=sizeof(Findit);
n=0;
while((Testthis->NAME[n]!='\0') && (n<=n1)){
//While Testthis->NAME here causes the exception
if(Testthis->NAME[n]=='-'){Testthis->NAME[n]=' ';}
n++;
}//end of while
// _PROGRAMの別の部分_ __ _
std::string Findme;
cout<<"Enter varible to find. Type quit to quit, case sensative."<<endl;
cin>>Findme;
char * writable = new char[Findme.size()+1];
std::copy(Findme.begin(),Findme.end(),writable);
writable[Findme.size()] = '\0';
if((Findme.compare("quit")!=0)^(Findme.compare("Quit")!=0)^(Findme.compare("QUIT")!=0)){
ProbableMatch(head,ccounter,writable);
}
delete [] writable;
// _ NODE_ ___
struct Node
{ public:
int VARID,counter,prob;
char NAME[64];
char DESCRIPTION[1024];
struct Node* next;
}node, *pNode=&node;
どのような目障りですか。これはCタグのためのものです。 – sbi
コードを減らして、関連性と形式を適切にしてください。 –
Testthis = new(Node); < - その行はバグのようです。どうして新しいNodeオブジェクトを割り当てるだけですぐ次の行でそれをリークするのですか? CurrentHighProb = new(Node)と同じことです。ここでポインタがどのように動作するかについては混乱があるようです。 –