|
The code provide what provides strcat , no less no more. I know strcat is a very dangerous function...
God once said: "The newbies should learn C pointers or go to Hell managed".
Moreover, since that was an interview question (see [^]), the OP was expected to have such a skill.
BTW My 5 for the 'skilled developer'.
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]
|
|
|
|
|
MVP 2010 - are they mad?
|
|
|
|
|
Hi,
How can we convert a modal dialog box into modaless dialog box and vice versa by adding some code. This was the one of the interview questions.
Thanks & Regards
msr
|
|
|
|
|
It's all explained in MSDN[^], your first port of call for Microsoft technical details.
MVP 2010 - are they mad?
|
|
|
|
|
MFC? CDialog::Create() for creating a modeless, and CDialog::DoModal() for spawning a modal dialog. But that's well explained in the documentation.
You'd have cleared the interview if you had read at least one good book on MFC. Any half decent book is bound to explain the concept of 'modality' of dialog boxes.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Hi
Please help me choose a component for the following task
I have C++ Win32-application (MS Visual C++ 2005 or 2008) that must:
- periodically (say once in 5 min) check a mailbox via POP3
- retrieve new messages from there, process them (the processing is specific for the my task) and remove the processed messages.
The processing converts body of received mail into plain text (WCHAR* string). I mean: to convert removing formatting elements like HTML tags (when a mail is in HTML format) etc., leaving only text. Now I am not interested in content of attachments - I need only mail's text.
The question is: do you know a component that can solve the task too? Or: one component to read POP3, another one for extracting text from received e-mail. The components may be commercial ones (my employer is rich enough to pay for them
|
|
|
|
|
Asking Google about "c++ pop3" offers many good ideas.
MVP 2010 - are they mad?
|
|
|
|
|
|
Member 2657521 wrote: The components may be commercial ones (my employer is rich enough to pay for them
Our products extensivly use email-crackers (we're doing EDI over Internet). Feel free to send me a private email.
|
|
|
|
|
#include <stdio.h>
struct Element{
int value;
struct Element *next;
};
struct Stack{
int length;
struct Element *head;
};
struct Stack createStack(){
struct Stack s;
s.length = 0;
s.head = NULL;
return s;
}
void push(struct Stack *stack, int value){
if (stack->head == NULL){
struct Element e = {value, NULL};
stack->head = &e;
}
else{
struct Element e = {value, stack->head};
stack->head = &e;
printf("(%d,%d)", stack->head->value, stack->head->next->value);
if (stack->head == stack->head->next)
printf("same");
}
stack->length++;
}
int main(){
struct Stack s = createStack();
int i;
for (i = 0; i < 10; i++)
push(&s, i);
return 0;
}
i m really having trouble while implement stack structure in C using pointer. here the problem is only with push function, lies on 2 lines:
struct Element e = {value, stack->head};<br />
stack->head = &e;
it seems that after i assigned stack->head to &e, the e->next(which was assigned to stack->head before) changes to be same with stack->head. lines bellow print results. can someone explain why? and how to fix it. thanks !
|
|
|
|
|
Firstly you already asked this question below, you should post further queries to the same thread.
Secondly you are using a local variable in the push() function which goes out of scope when you return, thus leaving you with a (potentially) corrupt structure.
Thirdly I think you need to spend some time studying structures, classes, pointers and other elements of C/C++.
MVP 2010 - are they mad?
|
|
|
|
|
|
i changed e to a global variable and using allocation, it runs well, many thanks!
|
|
|
|
|
It does? Have you checked the values in your stack?
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
|
MFC, VS6.0, C++
From within a thread I have used SendMessage() to flag an error and display an acknowledge dialog using AfxMessageBox, it's a simple 'An error has occurred press ok' kind of message and then it returns with return 0 eg:-
LRESULT CMainFrame::OnError(WPARAM wParam, LPARAM lParam)
{
switch (wParam)
{
case 1:
AfxMessageBox("Error 1 - Press OK");
break;
case 2:
AfxMessageBox("Error 2 - Press OK");
break;
}
return 0;
}
The problem is that the calling thread is 'hanging' after I click ok in the dialog box even though the only line after that is return 0. If I use PostMessage instead of SendMessage then the problem doesn't occur.
As I understand it SendMessage will wait until the message has been processed before continuing where PostMessage simply pops the message into the message queue and returns. I'm not quite sure what is going on here, obviously in the first case the message is not being flagged as completed so SendMessage never finishes but why? Any Ideas?
|
|
|
|
|
I suppose you hit this [^]:
Message Deadlocks
A thread that calls the SendMessage function to send a message to another thread cannot continue executing until the window procedure that receives the message returns. If the receiving thread yields control while processing the message, the sending thread cannot continue executing, because it is waiting for SendMessage to return. If the receiving thread is attached to the same queue as the sender, it can cause an application deadlock to occur. (Note that journal hooks attach threads to the same queue.)
Note that the receiving thread need not yield control explicitly; calling any of the following functions can cause a thread to yield control implicitly.
* DialogBox
* DialogBoxIndirect
* DialogBoxIndirectParam
* DialogBoxParam
* GetMessage
* MessageBox
* PeekMessage
* SendMessage
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]
|
|
|
|
|
So its probably AfxMessageBox() thats causing the problem then? I can check that easily enough by removing them temporarily I suppose...
|
|
|
|
|
Caslen wrote: So its probably AfxMessageBox() thats causing the problem then?
I suppose.
Caslen wrote: I can check that easily enough by removing them temporarily I suppose...
Let's try...
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]
|
|
|
|
|
Funnily enough it works ok with the MessageBoxes linked out!
I've added ReplyMessage as follows:-
LRESULT CMainFrame::OnError(WPARAM wParam, LPARAM lParam)
{
if (InSendMessage())
ReplyMessage(TRUE);
switch (wParam)
{
case 1:
AfxMessageBox("Error 1 - Press OK");
break;
case 2:
AfxMessageBox("Error 2 - Press OK");
break;
}
return 0;
}
and it works just fine, whats the difference between this and just using PostMessage though? Is it because it waits until the message is starting to be processed before replying and allowing the calling thread continue, where PostMessage just posts the message before allowing the calling thread to continue even though its possible that the message may not be processed?
|
|
|
|
|
When a SendMessage is being processed, the message loop of the receiving window (or thread) is still going and can process messages posted to it via PostMessages. Be aware that the notion that a PostMessage may not be processed is often misstated. The issue is whether the input queue on the receiving window is filled or not. This is a rare occurrence and indicates far bigger problems with your code if it is.
Do note that there is a SendMessageTimeout() function. I have never used it.
|
|
|
|
|
The message is definitely being processed as the message box is displayed correctly it's just not allowing/instructing/signalling the sending process that it has finished. For whatever reason the AfxMessageBox call is causing this to happen. I looked at SendMessageTimeout() too but I was more concerned as to why the sending thread wasn't continuing - SendMessageTimeout() would have been a workaround but I don't think I would have been better off than with PostMessage()
|
|
|
|
|
I prefer PostMessage() for something like this. The rule of thumb for SendMessage() is to do nothing that won't return in a few milliseconds AND to do no window operations in the call. As you've learned, don't open a message box or dialog box either.
|
|
|
|
|
Hi
How to get folder list on a root folder?
Thanks
Failure is Success If we learn from it!!
|
|
|
|
|
_findfirst() /_findnext()
FindFirstFile() /FindNextFile()
CFileFind
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|