|
I have started writing a game in C++ and while creating the login section of it I have come to a problem. I have it to where it gets the string and types it on the next line. But when it sends it to the save file it only shows up as little box symbols. I had it working before but i changed some things. then i changed them back and now it doesn't work. i can't find anything i forgot to take out or change.
--Blah
|
|
|
|
|
here is my code:
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#include "time.h"
char username[12];
int i, ch;
FILE *MyHandle;
char MyFile[12] = "Save.txt";
void main(void)
{
printf("Welcome.\n\n\n");
getch();
printf("Please identify yourself.\n");
printf("Name: ");
for( i = 0; (i < 12) && ((ch = getchar()) != EOF)
&& (ch != '\n'); i++ )
username[i] = (char)ch;
username[i] = '\0';
MyHandle = fopen( MyFile, "a+");
fprintf( MyHandle, "%s%c", username);
fclose( MyHandle);
printf("Welcome ");
printf( "%s", username);
printf( ". Go to the waiting room and await your orders.");
getch();
}
Blah
|
|
|
|
|
You are allowing up to 12 characters to be input for the name so username needs to hold 12 plus 1 for the '\0' character.
Zinzara wrote:
fprintf( MyHandle, "%s%c", username);
An additional byte is being popped from the stack with this. Either remove the %c , or add another parameter.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
thanks for your help. taking the %c out didn't help but i changed the "a+" to just "a" and it works now. again, thanks. well, i'm off to work on my game.
Blah
|
|
|
|
|
Zinzara wrote:
...taking the %c out didn't help...
While it may not have solved the exact problem you were having, having the "%c" in the format specifier was indeed an error.
Zinzara wrote:
...i changed the "a+" to just "a" and it works now...
I question this since the only difference between "a" and "a+" is how the EOF marker is handled.
You still need to chahge username from 12 to 13 so the '\0' character can be safely stored.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi,
I would like to know how to catch ESC key in MDI application. I tried with WM_KEYDOWN, WM_CHAR, But nothing seems to work. When ever any View is opend I able to catch ESC key on that view. But no view is opened nothing seems to work.
Thanks in Advance.
|
|
|
|
|
|
Newbie question here...
I am learning c++ and following through the code from a book - which recommends using Microsoft VC++ 7.0. The book stresses that it does not use the .net framework.
My question is can i use VS 2003 (.net) to create a "NON"-.net application? Would this be a "Win32 App" in visual studio?
help?
Thanks.
SN
|
|
|
|
|
Of course!! I've only experimented with the managed extensions a few times, but other than that, I just like the .Net IDE a lot better than VC6's. You can make any of the same application types that you could in VC6. And so far, any code or functions that I had in VC6 work with no problem. The difference if you just want to write C++ code without the .Net stuff is invisible to me. But at any time you can go into your project's properties and set 'Use Managed Extensions' to YES, which adds a \clr switch to your linker settings.
[insert witty comment here]
bdiamond
|
|
|
|
|
Thanks bdiamond! That's good to know.
What exactly are Managed Extensions?
SN
|
|
|
|
|
What exactly are Managed Extensions?
.net stuff...
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Managed extensions is the .Net BCL (Base Class Library). I guess it's almost like .Net's version of MFC. There is a great beginner's book I have by Tom Archer and Nishant Sivakumar (whom are both CodeProject members) that deals with a C++ programmer learning to use managed extensions. It's a great book, but I really haven't had the time to do more than a few exercises from it in the past few months.
[insert witty comment here]
bdiamond
|
|
|
|
|
Now i am a little confused....
"...at any time you can go into your project's properties and set 'Use Managed Extensions' to YES..."
As you posted earlier, i need to set 'Use Managed Extensions' to YES, but here you also say they are the .Net BCL.
If so wouldn't i NOT want to use Managed Extensions?
I'm being fussy i know... I just want to be sure i understand!
SN
|
|
|
|
|
I have a function that is handled for my listbox's double-click event. When a file in the list is double clicked it is opened in its default application. It was suggested by one of the users that I make this file read-only after it was opened so that if the user tried to then save a modification they would be reminded. Since the file is saved in the database, when my app closes, it goes through the temp folder and deletes all files that were open during this session. In case I also made it where it'll remove the read-only attribute and delete it if it's already there. The problem is that the BYTE buffer I allocate with the new operator is causing a memory leak, and when I try to call delete on it, I get an error in this section of code in "comip.h":
~_com_ptr_t() throw()<br />
{ <br />
_Release(); <br />
}
here's my function, with offending lines in bold:
BeginWaitCursor();
_RecordsetPtr rst;
strWhere.Format("LinkID = %d",data);
rst = theApp.GetRecordset(_T("*"),_T("tblLink") ,strWhere);
CString str,strPath;
FieldsPtr pFields = rst->GetFields();
FieldPtr pField,pName;
pField= pFields->GetItem(_T("FileBytes"));
pName = pFields->GetItem(_T("Link"));
unsigned long nLength = pField->GetActualSize();
str.Format("%s",(char*)_bstr_t(pName->Value));
_variant_t varBLOB = pField->GetChunk(nLength);
pBuf = new BYTE[nLength];
SafeArrayAccessData(varBLOB.parray,(void **)&pBuf);
pBytes = pBuf;
SafeArrayUnaccessData(varBLOB.parray);
::GetModuleFileName(NULL,szPath,512);
strPath.Format("%s",szPath);
int pos = strPath.ReverseFind('\\');
strDirectory = strPath.Left(pos + 1) + "temp\\";
strPath = strDirectory + url;
CreateDirectory(strDirectory,NULL);
CFile file;
CFileException ex;
CFileStatus status;
status.m_attribute = 0;
if(file.Open(strPath,CFile::modeRead,&ex))
{
file.Close();
CFile::SetStatus(strPath,status);
DeleteFile(strPath);
}
if(file.Open(strPath,CFile::modeCreate | CFile::modeWrite,&ex))
{
file.Write(pBytes,nLength);
file.Close();
file.GetStatus(status);
status.m_attribute |= 0x01;
CFile::SetStatus(strPath,status);
int iReturn = (int) ShellExecute(NULL, _T("open"), strPath, NULL, NULL, SW_SHOWNORMAL);
if (iReturn <= 32)
MessageBox (_T("Cannot open file. File may have been moved or deleted."), _T("Error!"), MB_OK | MB_ICONEXCLAMATION) ;
if(url.GetLength()==0)
MessageBox (_T("This is an empty entry! Try clicking a filled link! "), _T("Error!"), MB_OK | MB_ICONEXCLAMATION) ;
}
else
{
AfxMessageBox("File could not be opened from this location.\r\n"
"Check to make sure you don\'t already have this attachment open.",MB_ICONINFORMATION);
}
}
MYCATCHALL
url.ReleaseBuffer();
EndWaitCursor();
[insert witty comment here]
bdiamond
|
|
|
|
|
Hi,
Does anyone know how to write a text string on a video stream captured with the DirectX libraries in a way that the text is embedded in the stream ? In other words, it is possible to apply a text overlay on a video stream that will be saved with the stream ?
Any help would be greatly appreciated,
John
|
|
|
|
|
Hi,
Does anyone know how to write a text string on a video stream captured with the DirectX libraries in a way that the text is embedded in the stream ? In other words, it is possible to apply a text overlay on a video stream that will be saved with the stream ?
Any help would be greatly appreciated,
John
|
|
|
|
|
Hi i am tyring to build the sample console app using Zlib compression library.
I am getting linker error for following functions.
int __cdecl inflate_trees_fixed(...)<br />
void __cdecl zcfree(void *,void *)<br />
void * __cdecl zcalloc(void *,unsigned int,unsigned int)
for the first function inflate_trees_fixed(...) there is no function prototype in any of the file.
but it has following code in zconf.h file
<br />
#if defined(__MVS__)<br />
# pragma map(inflate_trees_free,"INTRFR")<br />
#endif <br />
AFAIK, if you are using #pragma map then you need not to define the function prototype.
Can someone throw light on this.
Thanks in advance.
Abhi Lahare
|
|
|
|
|
I have a listCtrl in report mode. Now I display a dialog to display/edit items when I double-click on an item in the list.
The problem is I would like to return to the dialog but with the selected item clearded down.
Currently as soon as I click on the dialog the last item is selected. I am using LVS_EX_FULLROWSELECT, so the full row is always selected.
Simply how do I unselect the selected row?
|
|
|
|
|
You need to clear that items selected state.
If you are using MCF:
m_LI.SetItemState (nItem, LVIS_SELECTED, LVIS_SELECTED);
m_LI.SetItemState (nItem, 0, LVIS_SELECTED);
m_LI.Invalidate ();
Otherwise:
LVITEM lvi;
memset (&lvi, 0, sizeof (lvi));
lvi.mask = LVIF_STATE;
lvi.stateMask = LVIS_SELECTED;
lvi.state = bSelected ? LVIS_SELECTED : 0;
SendMessage (hWndLI, LVM_SETITEM, 0, (LPARAM) &lvi);
Does that help?
Iain.
|
|
|
|
|
sweep123 wrote:
The problem is I would like to return to the dialog...
From where?
sweep123 wrote:
...the selected item clearded down.
What does "clearded down" mean?
sweep123 wrote:
Simply how do I unselect the selected row?
Call SetItemState(nItem, 0, LVIS_SELECTED) .
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
sweep123 wrote:
The problem is I would like to return to the dialog...
From where?
A Modeless Dialog (edit some fields on this row)
sweep123 wrote:
...the selected item clearded down.
What does "clearded down" mean?
When I next click on the dialog with the listctrl the last item is still selected.
sweep123 wrote:
Simply how do I unselect the selected row?
Call SetItemState(nItem, 0, LVIS_SELECTED).
That works when I display the Modeless dialog - thanks.
One other question, how do I force a complete redraw to the listctrl; say I need to show many changes?
Thanks for you post.
|
|
|
|
|
sweep123 wrote:
One other question, how do I force a complete redraw to the listctrl; say I need to show many changes?
If the items are kept in a data structure of some sort, you can just clear the contents of the list control and re-add them from the data structure. If you are just editing one item at a time, call SetItemText() after the modeless dialog is dismissed.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Thanks again for your post.#
I endd up using Invalidate() to redraw the list following data changes in the structure.
I use SetItemText for small changes.
I dont know if Invalidate() is OK to use.
|
|
|
|
|
i am trying to compling an oci program but keep getting these error messages:
Linking...
cdemorid.obj : error LNK2001: unresolved external symbol _OCIDescriptorAlloc
cdemorid.obj : error LNK2001: unresolved external symbol _OCIHandleAlloc
cdemorid.obj : error LNK2001: unresolved external symbol _OCILogon
cdemorid.obj : error LNK2001: unresolved external symbol "int __cdecl init_handles(struct OCIEnv * *,struct OCIError * *,int)" (?init_handles@@YAHPAPAUOCIEnv@@PAPAUOCIError@@H@Z)
cdemorid.obj : error LNK2001: unresolved external symbol _OCIEnvInit
cdemorid.obj : error LNK2001: unresolved external symbol _OCIInitialize
cdemorid.obj : error LNK2001: unresolved external symbol _OCIHandleFree
cdemorid.obj : error LNK2001: unresolved external symbol _OCILogoff
cdemorid.obj : error LNK2001: unresolved external symbol _OCIErrorGet
cdemorid.obj : error LNK2001: unresolved external symbol _OCIAttrGet
cdemorid.obj : error LNK2001: unresolved external symbol _OCIStmtFetch
cdemorid.obj : error LNK2001: unresolved external symbol _OCIDefineByPos
cdemorid.obj : error LNK2001: unresolved external symbol _OCIStmtExecute
cdemorid.obj : error LNK2001: unresolved external symbol _OCIAttrSet
cdemorid.obj : error LNK2001: unresolved external symbol _OCIStmtPrepare
cdemorid.obj : error LNK2001: unresolved external symbol _OCIBindByPos
Debug/cdemorid.exe : fatal error LNK1120: 16 unresolved externals
Error executing link.exe.
cdemorid.exe - 17 error(s), 1 warning(s)
|
|
|
|
|
did you well included the headers in the source files, and don't you use in you project some extern variables ?
TOXCCT >>> GEII power
|
|
|
|