If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Visual studio C++ 2008 MFC quiz app

I've been trying to make a little quiz application that takes questions from a file and them presents question by question on a static pannel, a few buttons that have the possible answers on them written as the questions go, and on the bottom a little place where we can see whats our score

when we finish the quiz, the score gets writen in a data.dat file and thats that

Re: Visual studio C++ 2008 MFC quiz app

The best thing to do is to post your code here so that we can have a look at it and provide comment and guidance. Without seeing the code that is causing the problem we can't really offer you much help. When you post code, please use code tags (Go Advanced, select code and click '#').

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Re: Visual studio C++ 2008 MFC quiz app

Originally Posted by 2kaud

The best thing to do is to post your code here so that we can have a look at it and provide comment and guidance. Without seeing the code that is causing the problem we can't really offer you much help. When you post code, please use code tags (Go Advanced, select code and click '#').

Code:

BOOL CQuizDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
char* pszFileName = "questions.txt";
CFile myFile;
CFileException fileException;
if ( !myFile.Open( "questions.dat", CFile::modeCreate |
CFile::modeReadWrite, &fileException ) )
{
TRACE( "Can't open file %s, error = %u\n",
pszFileName, fileException.m_cause );
MessageBox("Doesn't Work", "Doesn't Work", MB_OK); //This is just there so i can see if the file is not open
}
char szBuffer[5000];
UINT nActual = 0;
myFile.Seek( 0, CFile::begin );
nActual = myFile.Read( szBuffer, sizeof( szBuffer ) );
MessageBox(szBuffer, "foo", MB_OK); // This is here so i can see if the text is transfered here correctly
return TRUE; // return TRUE unless you set the focus to a control

Re: Visual studio C++ 2008 MFC quiz app

YES!

the file becomes empty as soon as i open the program

Code:

BOOL CQuizDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
char* pszFileName = "crap.txt";
CFile myFile;
CFileException fileException;
if ( !myFile.Open( pszFileName,CFile::modeRead, &fileException ) )
{
TRACE( "Can't open file %s, error = %u\n",
pszFileName, fileException.m_cause );
MessageBox("Doesn't Work", "Doesn't Work", MB_OK); //This is just there so i can see if the file is not open
}
char szBuffer[5000] = {0};
UINT nActual = 0;
//myFile.Seek( 0, CFile::begin ); // this over here made crap.txt an empty file
myFile.Read( szBuffer, sizeof( szBuffer ) );
MessageBox(szBuffer, "foo", MB_OK); // This is here so i can see if the text is transfered here correctly
return TRUE; // return TRUE unless you set the focus to a control
}

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.