no, no, no .... That's not the way to go!
You put some code with some syntax error and even some misconception in it.
That reveal that you are not understanding what your code has to do.
The compiler just gives some errors, but those errors are random as your code is. Attempting to fix those errors doesn't lead anywhere: you're never granted your code will do what you expect.
printf("Enter a string : ");
s is a pointer pointing to nowhere: where do ypu thoing your scanf can write to ?!? s[l]=0; tries to write to nowhere since s isnowhere a is a pointer to int, but you do a=(char*)malloc(l): what did you want to do? allocating char-s or int-s ?!
This is a mess of tokens with no syntax meaning! Raed about the for syntax, and understand the proper use of '()', ',', and ';'.
x=l-1 Wow... you're looking for problems: never use names like "O" and "l": I have to change font before find it's "l-1" and not "l-l" ... Do you get what I mean? If not, than that demonstrate the problem
Then: I see a malloc, but i don't see a free: not a good way to program...
I don't continue, but what can you do if you don't have clear in your mind what you're gonna do?
Thanks for vital information and suggestion.
I want to generate Combination of given String.Like this CString test="ABC", then generate like this
If you have any type solution or suggestion then please help me.
Ok, that's the problem. Now try to come to an algorithmic solution.
That doesn't need to be C or C++, just pseudocode.
Only when you find your algorithm looks meaningful, try to code it!
Than: the problem is not well formed. Do you want only two char-s combination? Does the input string needs to be 3 char-s wide or can it be whatever?
Be sure about that: you risk to produce a code that works on a very specific case, while looking for something more generic.
I am try to make number of possible key combination.I use google then i found number of example permutation and combination.There is common result in permutation and combination ignore repeated
Can any any help to permutation and combination ignore allowed?
What will happen to the memory allocated for "hello"? Will it be released at assignment of "world"?
Yes. The current content of a CString variable will be automatically released when the variable goes out of scope, as well.
Would someone like to explain why this has been 1-voted? The answer is correct. There may be some hedging involved as to whether new memory is actually allocated depending on the length of the two strings, as Joe pointed out, but the point is the reassignment of the variable will not result in a leak.
THAT was the question.
I assume the individual who voted it a 1 will now present some proof indicating that a leak WILL occur, justifying the 1?
CString is MFC class.
And the buffer it uses inside this class is handled by CString, it has nothing to do with user unless you are creating a pointer of the CString( Which is not at a good practice.)
Inside this CString class, destructor is having the code to delete the memory allocated for its internal buffer. So dont worrry, CString will delete that memory for you when it goes out of scope
It will release the memory of previously allocated pointer on the = operator of CString.
See the code of CString.
The specified function is called inside the = operator.
void CString::AllocBeforeWrite(int nLen)
if (GetData()->nRefs > 1 || nLen > GetData()->nAllocLength)
// This release will release all the memory allocated previously, so you wont face any memory leak.
ASSERT(GetData()->nRefs <= 1);
Hope you are now clear with it
Величие не Бога может быть недооценена.
modified on Monday, April 5, 2010 3:53 AM
Last Visit: 31-Dec-99 19:00 Last Update: 1-Feb-23 21:54