|
you don't do my home work just i want to know url link or forum name.i know why you do my home work.
thank
|
|
|
|
|
You can use casting, I know it's available in C++.
Don't know about C, does it have to be C or C++?
|
|
|
|
|
thank for make comment but sorry can you describe in detail.What's not available? please describe in detail.
|
|
|
|
|
i'm not sure if you've attempted to add float to an int data type, but you get compiler errors in the end.
you want to add float and int to each other.
Casting:
int x = 12;
float y = 4.0;
int sum = x + (int)y;
|
|
|
|
|
Thank for reply but it's not useful for me because where i use int + float.If you have solution then please help me.
|
|
|
|
|
Hi all,
i want to generate max. combination for any given value.
like for AB::
combinations are "AB";"BA";"AA";"BB"
i m using Permutation but it gives only 2 combination here.
so please help me for this.
thanks in advance.
|
|
|
|
|
Show your code.
Величие не Бога может быть недооценена.
|
|
|
|
|
int fac(int n)
{
if (n == 0) return 1;
else return n*fac(n - 1);
}
void permute(char *string, int n, int rank)
{
vector<char> vec;
for (int ctr = 0; ctr < n; ctr++) vec.push_back(string[ctr]);
for (int ctr = n; ctr >= 1; ctr--)
{
int quotient = rank/fac(ctr-1);
char c = vec[quotient];
vec.erase(vec.begin()+quotient);
*string++ = c;
rank%=fac(ctr-1);
}
}
void showpermutes(char *string)
{
char temp[20];
int n = strlen(string);
if (n > 19) return;
int nfac = fac(n);
for (int ctr = 0; ctr < nfac; ctr++)
{
strcpy(temp, string);
permute(temp, n, ctr);
cout << temp << endl;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
showpermutes("AB");
system("PAUSE");
getche();
return 0;
}
|
|
|
|
|
|
its not display any combination.
|
|
|
|
|
You mean this article is not good?
but i felt this is what you are looking for.
Величие не Бога может быть недооценена.
|
|
|
|
|
No this is not my mean,
i mean to say that its diplay the number of combination instead of all diffrent combination.
i really need all cobination,not the number of combination.
as i already mention in my thread.
like for::
AB i want "AB";"BA";"AA";"BB";
if this code generate this type of combinations please tell me how can i do this.
thanks.
|
|
|
|
|
You may go recursive for that.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi All
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?
Like CString test="AB";
out put->
AB
BA
AA
BB
Please help me
|
|
|
|
|
You may go recursive for that.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi,
Do the following will cause memory leak?
CString temp; //global variable
temp = "hello"; //Assignment 1
temp = "world"; //Assignment 2
What will happen to the memory allocated for "hello"? Will it be released at assignment of "world"?
Thanks
JC
|
|
|
|
|
TechAvtar wrote: 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.
[edit]
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?
[/edit]
L u n a t i c F r i n g e
|
|
|
|
|
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
Величие не Бога может быть недооценена.
modified on Monday, April 5, 2010 3:06 AM
|
|
|
|
|
But what if the usage is as below? The variable temp is not going out of scope.
Will it cause leak?
CString temp; //global variable
while(1)
{
temp = "hello"; //Assignment 1
temp = "world"; //Assignment 2
}
|
|
|
|
|
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)
{
Release();
AllocBuffer(nLen);
}
ASSERT(GetData()->nRefs <= 1);
}
Hope you are now clear with it
Величие не Бога может быть недооценена.
modified on Monday, April 5, 2010 3:53 AM
|
|
|
|
|
Since "world" is the same length as "hello", no reallocation will be done; "world" will just overwrite "hello".
If you set a string "hello world", the internal buffer would be reallocated in a safe manner, resulting in no leak. (For optimization reasons, CString sometimes allocates a larger buffer than requested, so even setting a larger string won't result in a reallocation.)
|
|
|
|
|
I've written a Win32 application that runs and displays a window, but I'm trying to run a second window.
After pressing a button or any other similar event.
The problem is that everywhere I looked, the second dialog was created using the Dialog function.
I was wondering is their any possible way to start one using Win32 API.
Appreciate any notes on this matter/subject.
|
|
|
|
|
Hia.
Yeah, sure this is possible - in perhaps fewer lines of code than you may expect.
You'll want to declare a static HWND in the windowProcedure for the first window, or declare it as a global.
Then it's just a matter of creating the new window.
I keep a flag that tells me if the child window currently exists or not, then I act accordingly - either setting the window text, or creating the window.
if (!isChildOpen)
{
GetWindowRect(hwndDlg, &myRect);
imgChildHWND = CreateWindowEx(0, "picWnd", myWad.getLumpName(resNum), WS_SYSMENU|WS_CAPTION|WS_POPUP|WS_VISIBLE|WS_CHILD, myRect.right, myRect.top, 300, 300, hwndDlg, NULL, hInst, 0);
isChildOpen = true;
}
else
SetWindowText(imgChildHWND, myWad.getLumpName(resNum));
The child window sends a message to the controlling window whenever it is closed so I know if the window is open or not without resorting to findWindow,
i.e
case WM_CLOSE:
PostMessage(GetParent(hwnd), IDC_CHILDCLOSING, 0, 0);
Where IDC_CHILDCLOSING is a message I've defined (#define IDC_CHILDCLOSING 1011)
|
|
|
|
|
I got it to work thank you very much.
However their is other problems.
How will I differentiate the window messages between parent and child window.
For the controls, parent has a ListView child has a ComboBox.
|
|
|
|
|
That's okay, it's my pleasure.
Each window receives messages from its own controls, so the parent gets WM_NOTIFY and LVN_xxxxxx messages, while the child window gets WM_COMMAND and CBN_xxxxxxx messages.
The key to the scheme is that you need to treat the child window like a custom control, and remember to pass messages from it to it's parent window. You'll need to tell the parent
when something in the child window has happened - e.g a combobox event, you may also wish to send messages from the parent to the child - e.g take this array of strings and add each one to the combobox.
In short, just think of the child window as a control and remember to pass messages between the control and it's parent whenever something needs to be done(e.g fill combo with array of strings), or whenever something has happened (e.g chosen item in combobox has changed)
|
|
|
|