-
June 10th, 2013, 03:52 PM
#1
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
-
June 10th, 2013, 06:23 PM
#2
Re: Visual studio C++ 2008 MFC quiz app
-
June 10th, 2013, 08:24 PM
#3
Re: Visual studio C++ 2008 MFC quiz app
Originally Posted by GCDEF
Have fun.
thanks
-
June 10th, 2013, 08:33 PM
#4
Re: Visual studio C++ 2008 MFC quiz app
anyway, can someone post me something that might help?
google didnt, irc networks didnt, other forums didnt
codeguru is someone i consider that might help at least in pointing me on how to do it properly
-
June 10th, 2013, 09:00 PM
#5
Re: Visual studio C++ 2008 MFC quiz app
The best way to get help is to ask a specific question about a problem you're having.
-
June 11th, 2013, 04:34 AM
#6
Re: Visual studio C++ 2008 MFC quiz app
Originally Posted by GCDEF
The best way to get help is to ask a specific question about a problem you're having.
i have a problem with opening files and copying the whole text into a string
i get something like this: http://i.imgur.com/LpiYXHl.png Im thinking this has something to do with unicode file misconceptions
altho i've tried to do this without the file, and getting the text on the static was imposible, and getting some text on the button
i think i know how to make the score system work but im not sure about that ether
-
June 11th, 2013, 05:49 AM
#7
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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
June 11th, 2013, 08:13 AM
#8
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
http://i.imgur.com/oSQo9Hr.png
i got this monstrocity of an error, its been driving me crazy, and yes i've tried changing the encoding of the questions.txt, even tried different extensions
-
June 11th, 2013, 08:34 AM
#9
Re: Visual studio C++ 2008 MFC quiz app
You're reading the file without ever writing to it, so you're just displaying an uninitialized buffer.
Why are you setting pszFileName to "questions.txt", then hard coding "questions.dat" in the open call?
Last edited by GCDEF; June 11th, 2013 at 08:36 AM.
-
June 11th, 2013, 08:42 AM
#10
Re: Visual studio C++ 2008 MFC quiz app
1) CFile::modeCreate empty's the file, so as GCDEF mentioned, there is nothing read into the buffer.
2) you need to NULL terminate the buffer
-
June 11th, 2013, 09:21 AM
#11
Re: Visual studio C++ 2008 MFC quiz app
Originally Posted by GCDEF
You're reading the file without ever writing to it, so you're just displaying an uninitialized buffer.
Why are you setting pszFileName to "questions.txt", then hard coding "questions.dat" in the open call?
because there was previously an error when i did it with the string, the error is gone for some reason
1) CFile::modeCreate empty's the file, so as GCDEF mentioned, there is nothing read into the buffer.
2) you need to NULL terminate the buffer
explane 2) please
-
June 11th, 2013, 09:51 AM
#12
Re: Visual studio C++ 2008 MFC quiz app
Many routines that process character strings require a NULL character to indicate the end of the string.
Otherwise, the routine would not know when to stop processing.
In your case, the simplest way:
Code:
char szBuffer[5000] = {0};
However, if the actual number of characters read in is 5000, you need
to set szBuffer[4999] to NULL.
-
June 11th, 2013, 10:06 AM
#13
Re: Visual studio C++ 2008 MFC quiz app
Philip Nicoletti
now there is no text at all, i think this is a good sign
-
June 11th, 2013, 10:08 AM
#14
Re: Visual studio C++ 2008 MFC quiz app
Originally Posted by Joe412
Philip Nicoletti
now there is no text at all, i think this is a good sign
No it's not. You're still trying to read an empty file (I assume). The NULL just stops the garbage being displayed.
-
June 11th, 2013, 10:16 AM
#15
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
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|