wireFrame9
Technical User
I wrote the program initially for console. The contents of the onButton1 method should add an element to a linked list. It WORKS in the console. All I did was to copy the contents of the console function to the onButton1 method. I also copied the structure definition and the declaration of pointers as is.
OnButton2 is used to check that the first 2 elements were entered correctly, which I input their ->value as 0 and 7.
It sometimes crashes with illegal operation. Sometimes it doesn't, but adding only 1 element, and sometimes it works!!
#include "stdafx.h"
#include "112.h"
#include "112Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
class mintermTag
{
public:
int value;
int group;
int isEssential;
int coverage;
mintermTag *next;
};
mintermTag *headMintermA, *headMintermB, *newMinterm, *nextMinterm,
*currentMinterm, *currentMinterm2, *temporaryMinterm,
*nextGroupMinterm, *headOfEssentials;
/////////////////////////////////////////////////////////////////////////////
// CMy112Dlg dialog
CMy112Dlg::CMy112Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CMy112Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMy112Dlg)
m_nScannedValue = 0;
m_nNumberOfVariables = 4;
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMy112Dlg:
oDataExchange(CDataExchange* pDX)
{
CDialog:
oDataExchange(pDX);
//{{AFX_DATA_MAP(CMy112Dlg)
DDX_Text(pDX, IDC_EDIT1, m_nScannedValue);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMy112Dlg, CDialog)
//{{AFX_MSG_MAP(CMy112Dlg)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy112Dlg message handlers
BOOL CMy112Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMy112Dlg::OnButton1()
{
UpdateData(TRUE);
// if ( !test_input_validity(decimalValue) )
// return 101;
int decimalValue = m_nScannedValue;
int requiredGroup;
int numberOfOnes = 0;
while (decimalValue)
{
if ( decimalValue& 1 )
numberOfOnes++;
decimalValue = decimalValue>>1;
}
requiredGroup = numberOfOnes;
// if ( check_existance(decimalValue, requiredGroup) )
// return 102;
newMinterm = new mintermTag;
newMinterm->value = decimalValue;
newMinterm->group = requiredGroup;
newMinterm->isEssential = 1;
newMinterm->coverage = 0;
while ( currentMinterm->next != NULL)
currentMinterm = currentMinterm->next;
currentMinterm->next = newMinterm;
newMinterm->next = NULL;
}
else
{
currentMinterm = headMintermA;
nextMinterm = currentMinterm->next;
while ( ( currentMinterm->group != requiredGroup )
&& ( nextMinterm->group <= requiredGroup )
&& ( nextMinterm != NULL ) )
{
currentMinterm = currentMinterm->next;
nextMinterm = currentMinterm->next;
}
if ( currentMinterm->next != NULL )
{
newMinterm->next = currentMinterm->next;
currentMinterm->next = newMinterm;
}
else
{
newMinterm->next = NULL;
currentMinterm->next = newMinterm;
}
}
}
void CMy112Dlg::OnButton2()
{
CString YES = "HELLOW WORLD!";
int counter = 0;
currentMinterm = headMintermA;
if ( currentMinterm->value == 0 )
counter++;
currentMinterm = currentMinterm->next;
if ( currentMinterm->value == 7 )
counter++;
if ( counter == 2 )
MessageBox(YES);
}
OnButton2 is used to check that the first 2 elements were entered correctly, which I input their ->value as 0 and 7.
It sometimes crashes with illegal operation. Sometimes it doesn't, but adding only 1 element, and sometimes it works!!
#include "stdafx.h"
#include "112.h"
#include "112Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
class mintermTag
{
public:
int value;
int group;
int isEssential;
int coverage;
mintermTag *next;
};
mintermTag *headMintermA, *headMintermB, *newMinterm, *nextMinterm,
*currentMinterm, *currentMinterm2, *temporaryMinterm,
*nextGroupMinterm, *headOfEssentials;
/////////////////////////////////////////////////////////////////////////////
// CMy112Dlg dialog
CMy112Dlg::CMy112Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CMy112Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMy112Dlg)
m_nScannedValue = 0;
m_nNumberOfVariables = 4;
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMy112Dlg:

{
CDialog:

//{{AFX_DATA_MAP(CMy112Dlg)
DDX_Text(pDX, IDC_EDIT1, m_nScannedValue);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMy112Dlg, CDialog)
//{{AFX_MSG_MAP(CMy112Dlg)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy112Dlg message handlers
BOOL CMy112Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMy112Dlg::OnButton1()
{
UpdateData(TRUE);
// if ( !test_input_validity(decimalValue) )
// return 101;
int decimalValue = m_nScannedValue;
int requiredGroup;
int numberOfOnes = 0;
while (decimalValue)
{
if ( decimalValue& 1 )
numberOfOnes++;
decimalValue = decimalValue>>1;
}
requiredGroup = numberOfOnes;
// if ( check_existance(decimalValue, requiredGroup) )
// return 102;
newMinterm = new mintermTag;
newMinterm->value = decimalValue;
newMinterm->group = requiredGroup;
newMinterm->isEssential = 1;
newMinterm->coverage = 0;
while ( currentMinterm->next != NULL)
currentMinterm = currentMinterm->next;
currentMinterm->next = newMinterm;
newMinterm->next = NULL;
}
else
{
currentMinterm = headMintermA;
nextMinterm = currentMinterm->next;
while ( ( currentMinterm->group != requiredGroup )
&& ( nextMinterm->group <= requiredGroup )
&& ( nextMinterm != NULL ) )
{
currentMinterm = currentMinterm->next;
nextMinterm = currentMinterm->next;
}
if ( currentMinterm->next != NULL )
{
newMinterm->next = currentMinterm->next;
currentMinterm->next = newMinterm;
}
else
{
newMinterm->next = NULL;
currentMinterm->next = newMinterm;
}
}
}
void CMy112Dlg::OnButton2()
{
CString YES = "HELLOW WORLD!";
int counter = 0;
currentMinterm = headMintermA;
if ( currentMinterm->value == 0 )
counter++;
currentMinterm = currentMinterm->next;
if ( currentMinterm->value == 7 )
counter++;
if ( counter == 2 )
MessageBox(YES);
}