|
In addition to what hfry said you have to take into account the difference between delete and delete[] . If you allocate an array with new[] delete it with delete[] .
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Should read:
bin = new char[size+1];
You need to allocate space for the NULL terminator.
Steve
|
|
|
|
|
The main reason you're getting the crash is because you're using the wrong deallocator.
If you use new[] to allocate memory, than you need to use delete[] to deallocate the memory.
The debug version will give you a runtime error, where as the release version will ignore the problem.
Top ten member of C++ Expert Exchange.
http://www.experts-exchange.com/Cplusplus
|
|
|
|
|
Axter wrote: The main reason you're getting the crash is because you're using the wrong deallocator.
If you use new[] to allocate memory, than you need to use delete[] to deallocate the memory.
The program will not crash due to mismatch b/w new[] and delete but there will be memory leak
never say die
|
|
|
|
|
sunit5 wrote: The program will not crash due to mismatch b/w new[] and delete but there will be memory leak
Then how do you define a memory leak?
VuNic
|
|
|
|
|
No doubt memory leak can cause crash.
Axter wrote:
The main reason you're getting the crash is because you're using the wrong deallocator.
but i wanted to highlight the using delete in place of delete[](when using new[])the program will not crash when executing it.
never say die
-- modified at 6:59 Monday 27th March, 2006
|
|
|
|
|
using delete[] as opposed to delete made no difference. You also mention that it can cause memory leaks, yet none of my leak detectors can find any. I suppose if I were to allocate multidimentional arrays then I may have a problem with leaks, but I'm not doing that here.
As a previous poster said, the problem was due to not allocating enough space. Adding the +1 fixed everything.
|
|
|
|
|
using delete instead of delete[] with new[] will delete only the first memory location (returned by new[]).What about the rest of the memory.Can u use it?
never say die
|
|
|
|
|
Using the sprintf and printf functions, the %s,%i.. flags are normally replaced. Hey no problem, But what If I want a Percent sign '%' in the string?
escaping it '\%' gives errors, and simply leaving it causes the function to remove it.
|
|
|
|
|
to print a percent-sign character, use %%
|
|
|
|
|
Hi,
I know that if you want to put a '\' character in your string ,you should use "\\" instead(e.g. fprintf("c:\\"program files" , ...)) , so try use double % in your string(i'm not sure it's working but give it a try....).
Regards,
Eli
|
|
|
|
|
Thankyou guys, I finaly got that thawn out my backside. the %% worked, but I first did it another way: sprintf("percent '%s","%");
It worked but now I know the right way.
|
|
|
|
|
Hi,
I've got a (probably) common problem: I want to create a several unmanged C++ DLLs in VS2005, most of them shall export functions with strings (best CString), like this:
void TestFunc1(int a, CString b);
void TestFunc2(int a, LPCTSTR b);
CString TestFunc3(int a);
All these DLLs compile and link well, but when I try to use them in my applications, I always receive a linker error (LNK2019: undefined external symbol). Obviously, this problem is related to the use of strings as arguments (or return values), because if I remove them as arguments, everything works fine...
any ideas how to solve this?
Greetings,
Peter
|
|
|
|
|
Have you created an MFC or a regular dll? MFC dlls can only be used from MFC applications. If you want to use the functions from a not-MFC application, replace CString with string.
|
|
|
|
|
Interesting assignment, thanks for sharing
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Hi All,
Here I am with yet another question. I am streaming text to and from a rich edit control (Not RTF format). The text in the control has all the formatting capabilities as documented by MS.
Formatting suxh as CTRL+TAB, is easy enough since a tab character is inserted into the control, then I can use STREAMOUT to get a tabified string. The problem is, I'm not sure how to deal with CTRL+E,B,U etc... Since nothing is really visible.
I want to stream out this text with the formatting, store it and recreate it again. Is this possible to do with non-RTF text, or will I have to start converting?
|
|
|
|
|
I need to write a wordlist class that inserts text into a binary search tree for processing. I have written a binary search tree class (below) and can input text directly into it but I am having a problem creating a wordlist class to do it. The wordlist class would also keep track of the total number of words in the list and the number of occurrences of each word. What would that class look like? Any suggestions would be greatly appreciated. Thanks.
template <class item="">
class bst_node
{
public:
// TYPEDEF
typedef Item value_type;
// CONSTRUCTOR
bst_node(
const Item& init_data = Item( ),
bst_node* init_left = NULL,
bst_node* init_right = NULL
)
{
data_field = init_data;
left_field = init_left;
right_field = init_right;
}
// MODIFICATION MEMBER FUNCTIONS
Item& data( ) { return data_field; }
bst_node* &left( ) { return left_field; }
bst_node* &right( ) { return right_field; }
void set_data(const Item& new_data) { data_field = new_data; }
void set_left(bst_node* new_left) { left_field = new_left; }
void set_right(bst_node* new_right) { right_field = new_right; }
// CONST MEMBER FUNCTIONS
const Item& data( ) const { return data_field; }
const bst_node* left( ) const { return left_field; }
const bst_node* right( ) const { return right_field; }
private:
Item data_field;
bst_node *left_field;
bst_node *right_field;
};
// NON-MEMBER FUNCTIONS for the bst_node<item>:
template <class item="">
void insert(bst_node<item>* &node_ptr, Item new_data);
template <class item="">
void print(const bst_node<item>* node_ptr);
template <class item="">
int tree_size(const bst_node<item>* node_ptr);
|
|
|
|
|
If code is posted without formatting (indentation) it's too painful to bother with.
Steve
|
|
|
|
|
if I use barcode fonts in my App, I think users can not use my App because they didn't install those fonts.
any free barcode fonts for download?
A nice hyper tool for optimizing your Microsoft html-help contents.
A best image tool for Windows C++ programmers, don't miss it!.
Includeh10
|
|
|
|
|
I'm a complete beginner with C++. I'm trying to get some sample programs that use DirectX (specifically DDraw) to compile using VC++ 6, but it's making my head hurt. Is there an idiot's guide to exactly what I have to do set everything up? Or can someone help me?
So far I've:
Downloaded & installed DirectX SDK 10
Fired up VC++ 6 and:
Tools\Options\Directories - added the \SDK\Include path to the "Include files" drop down & added the \SDK\x64 and \SDK\x86 paths to the "Library files" drop down
Project\Settings\Link - added "ddraw.lib" to the "Object/Library modules"
Obviously something's wrong though, as the sample I'm trying to compile comes back with a "error C2146: syntax error : missing ';' before identifier 'lpdd'" when it gets to the first of the list of externals ("extern LPDIRECTDRAW4 lpdd; ")
I've combed the web to the best of my ability and there seems to be lots of advice on setting up Borland and DevC++ to use DirectX, but I can't find a word about Visual C - I assume I'm being stupid.
|
|
|
|
|
I believe DirectDraw isn't officially supported since DX8. That means you still can use it, but you won't find documentation for it (last is in DX7 SDK I believe). Make sure you're on WXP as AFAIK that's what DX10 needs.
Also, I believe LPDIRECTDRAW4 is surely older interface than necessary, try LPDIRECTDRAW7 or LPDIRECTDRAW6.
As for setting up VC 6.0: set up the prober include and library directories as you did. Move them both to the top of the list! Otherwise, it won't work (at least with DX8 I've been using). You also need to link some libs... like ddraw.lib and maybe dxguid.lib, depending on what parts of DX you use (look in the libs directory and use common sense).
I believe you should better use D3D to draw graphics. As for links, gamedev.net has some nice articles and good forums for this kind of stuff (in the forum FAQ for D3D, you can even find links to some page that has older SDK for download if you want DD documentation). A nice tutorial is at http://www.andypike.com/tutorials/ . If you just want to do 2D with D3D, look up Sprites in the SDK. Also, there are some nice tutorials in the SDK's help files.
Haven't touched DX since DX8/9, so if there's something new specifically to DX10, sorry
|
|
|
|
|
Thanks very much indeed - moving the includes to the top of the list did the trick. Maybe in years to come I'll understand exactly what the linker is doing, when & why....
And thanks for all the other tips. I'm only using LPDIRECTDRAW4 because I'm cutting and pasting samples from an old Andre Lamothe book (Tricks of the Windows Game Programming Gurus). I'll try updating it and thanks too for the link.
|
|
|
|
|
Could any tell me how I display a float value in a message box.
Your result is: 1234567.5678 - for example
Many Thanks
Steve
|
|
|
|
|
I think you use to convert Numeric to String
Example:
int a=123;
TCHAR Buffer[50];
itoa(a,Buffer,10);
MessageBox(Buffer);But if you use 123.23->result 123
|
|
|
|
|
WhiteSky wrote: Example:int a=123;TCHAR Buffer[50];itoa(a,Buffer,10);MessageBox(Buffer);But if you use 123.23->result 123
what about CString::Format or wsprintf command
|
|
|
|