|
Hi,
Can somebody please point out why I'm getting a heap corruption error for the below code? I'm free all of the resources I've allocated with malloc.
Thanks
void TestMultiDim()
{
char** mArray;
int rows = 50;
char* p;
char* q;
int i;
char* data = "John Doe";
size_t len;
len = rows * sizeof(char*);
mArray = (char **)malloc(len);
if(mArray == NULL)
{
exit(EXIT_FAILURE);
}
for(i = 0; i < rows; i++)
{
mArray[i] = (char*)malloc(len);
if(mArray[i] == NULL)
{
exit(EXIT_FAILURE);
}
}
for(i = 0; i < rows; i++)
{
mArray[i] = data;
}
for(i = 0; i < rows; i++)
{
printf("%s\n", mArray[i]);
}
for(i = 0; i < rows; i++)
{
free(mArray[i]);
mArray[i] = NULL;
}
free(mArray);
}
|
|
|
|
|
Due to this line :
gp343 wrote: mArray[i] = data;
The reason is that you are changing the pointer at mArray[i] to that of data. Now data was noy dynamically allocated and moreover all mArray[i] points to same data. So free will fail. For copying string you should use.
strcpy(mArray[i], data);
-Saurabh
|
|
|
|
|
Sauraub, many many thanks for this. It worked!
|
|
|
|
|
You are most welcome.
-Saurabh
|
|
|
|
|
Hi all,
i m creating a resizable propertysheet with the help of this article.
http://support.microsoft.com/kb/325613[^]
But i have one problem.
In my Propertysheet the three buttons are created,those are "OK","CANCEL",and "APPLY",Apply button is disabled.
but i dont want all these button so please tell me how can i do this.
how can i remove all these buutons.
Thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
ThatsMe. wrote: In my Propertysheet the three buttons are created,those are "OK","CANCEL",and "APPLY",Apply button is disabled.
but i dont want all these button so please tell me how can i do this.
You can call SetWizardButtons method of CPropertySheet and set appropriate buttons.Typically it's called from CPropertyPage::OnSetActive .
Another option for you is to directly use control ids in a property page/sheet to hide or disable them as you need, control ids are...
ID_APPLY_NOW
ID_WIZBACK
ID_WIZNEXT
ID_WIZFINISH
AFX_IDC_TAB_CONTROL or use GetTabControl
Another function that might interest you is CPropertySheet::SetFinishText .
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
modified on Saturday, June 14, 2008 3:54 AM
|
|
|
|
|
After this please tell me how can close the Property sheet when i click the button of Property page.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
How about EndDialog() ?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
i m using this but the property sheet not closed.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
Hi all,
I installed VC6 with SP6 on my Vista x64 system and have noticed the following problem with my MFC application. When I run in debug mode and am stopped at a breakpoint (or the debugger has stopped because of an error), and then I press Shift-F5 to stop debugging, then the IDE will return to it's normal non-debug state but my application will not be stopped. I can see the application in the task bar but just get the error dialog "This program is not responding" when I try to close it.
After the problem occurs I cannot make changes to any files because I get the following link error when I try to rebuild: LNK1168: cannot open [filename].dll for writing.
The application will close properly if I use Shift-F5 from the IDE when the debugger is not at a breakpoint. Also if I close and restart the IDE the zombie processes will be closed as well but this is not an ideal workaround. Does anyone know how to properly fix the problem so the application will always be closed when I use Shift-F5 (this is what used to happen when I was working on my Win2000 system).
Thanks,
Kevin
|
|
|
|
|
I've never used x64, but I haven't seen that problem on Vista x86. Are you running VC6 elevated? VC6 (and its MSDN) need to be run elevated to work properly.
|
|
|
|
|
Hi Mike,
> Are you running VC6 elevated? VC6 (and its MSDN) need to be run elevated to work properly.
No, I'm not doing this. (In fact I just turned off User Account Control to get things going without all of the Vista prompts.) Can you point me in the right direction to set this up?
Thanks,
Kevin
|
|
|
|
|
Right click on executable and then chose "Run as Administrator".
-Saurabh
|
|
|
|
|
I tried running VC6 as administrator but it seems to make things worse - VC++ crashes when I close my app after running it in debug mode.
|
|
|
|
|
I think I had this error but do you have this problem with your all projects or with this project?
|
|
|
|
|
I've only been working with the one project so far so I'm not sure what happens with other projects. If I can't figure out the problem I might try testing with another project. Is there something in the project settings that you think might be causing the problem?
|
|
|
|
|
On the property pages of your project go to Linker and see does "Generate Debug Info" set to "Yes(/DEBUG)" or no?
|
|
|
|
|
The setting for "generate debug info" is turned on.
|
|
|
|
|
Answer to some errors is difficult without see source code but you have two ways:first you can send your project to me(of course Im using of Visual Studi 2008),but if you dont like,you can make a new project and start to copy your functions to new project for find error.
|
|
|
|
|
Are you logging in with an admin account? In that case, everything you run is elevated just like in XP. If you're using a regular user account, you can use Run As Administrator, but be aware that the app will then run in the context of a different account, and it may not behave as you expect (eg it will save options under the admin's per-user area, not your account's area).
|
|
|
|
|
I'm logging in with an admin account so it seems like the problem must be caused for some other reason.
|
|
|
|
|
I know this probably is the worlds most simple and stupid question, yet I'm having a pretty hard time figuring out what it means.
some simple code:
int some_variable;
some_variable =! some_variable;
What does =! mean!?
And what is that kind of assigning called? Just so i'm able to look up more info about it...
|
|
|
|
|
bool b = false;
bool not_b_1 = !b;
bool not_b_2 =! b;
and now, not_b_1 == true and not_b_2 == true
|
|
|
|
|
Thanks man
|
|
|
|
|
Jan Sommer wrote: What does =! mean!?
This might help. It assigns the "not" value of some_variable .
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|