Thread: Why isn't this working?

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001

    Why isn't this working?

    int SaveClientInfo(HWND DialogHandle)
    	Client Cliente;
    	HWND NameEditBoxHwnd;
    	HWND NameEditBox;
    	char * NameOfFile;
    	char *FileToSave;
    	char *NameOfClient;
    	int iCount;
    	NameEditBoxHwnd=GetDlgItem(DialogHandle, IDC_NOMBRE);
    	//we incremente iCount to accomodate for the NULL character
    	NameOfFile=new char [sizeof(iCount)];
    	FileToSave= new char [sizeof(NameOfFile)];
        OpenFileName.hwndOwner         = NULL;
        OpenFileName.lpstrFile         = NameOfFile;
    	OpenFileName.lpstrFileTitle	   =FileToSave;
    	GetSaveFileName (&OpenFileName);
    	NameEditBox=GetDlgItem(DialogHandle, IDC_NOMBRE);
    	//we incremente iCount to accomodate for the NULL character
    	NameOfClient=new char [sizeof(iCount)];
    	ofstream fout(OpenFileName.lpstrFileTitle);
    	fout.write((char*)&Cliente,sizeof Cliente);
    	delete NameOfFile;
    	delete FileToSave;
    	delete NameOfClient;
    	/* I am having some serious problems with this stuff
    	upon closing the window the program crashes....
    	how would I free the pointer memory? 
    	delete Pointer;
    	Should  I do this here? 
    	Remember taht this is called more than once thruout the program
    	I think that it's because I am not freeing memory properly
    	return Success;
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.

    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > NameOfFile=new char [sizeof(iCount)];
    Which is pretty much the same as
    NameOfFile=new char [sizeof(int)];

    You probably meant
    NameOfFile=new char [iCount];

    Or maybe
    NameOfFile=new char [iCount+1];

    The other sizeof() is probably wrong as well for much the same reason
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function not working
    By sloopy in forum C Programming
    Replies: 31
    Last Post: 11-12-2005, 08:08 PM
  2. Program Not working Right
    By raven420smoke in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2005, 03:21 AM
  3. Trying to eject D drive using code, but not working... :(
    By snowfrog in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2005, 07:47 PM
  4. x on upper right corner not working
    By caduardo21 in forum Windows Programming
    Replies: 1
    Last Post: 02-20-2005, 08:35 PM
  5. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 04:08 AM