|
Well, I think that the creation and printing is the same for each list, but the other functions (i.e. adding or deleting a node have slight differences for each kind of a list)
And I thought it was about that, about adding them before main, but it's the same, create list and print list functions work in both ways, but the last one doesn't work on either way, I have mistake in the transition from node to node . Anyway thanks for your reply.
|
|
|
|
|
Naumf wrote: node *create_list();
void print_list(node *);
int sum_of_even(node *);
Move main() below all the other functions and these prototypes can be removed.
Naumf wrote: while(x!=-1)
{
p=new node;
p->link=q;
p->info=x;
q=p;
cin>>x;
}
This while() loop is odd. How about:
while (x > 0)
{
...
x--;
} Since print_list() goes through the list okay, why not model sum_of_even() after it?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
It is the same for the prototypes, It is important to declare them before you use them, and my first two functions work OK, but I have a problem with the code in the last one sum_of_even(). And about the while loop, I use both of them, but I've included this one now. Any help about the last function? BTW thanks for your reply.
|
|
|
|
|
Naumf wrote: It is the same for the prototypes, It is important to declare them before you use them,
Yes, but only if they are located elsewhere. In your case, they are definitely not needed. Just move main() to the bottom.
Naumf wrote: ...but I have a problem with the code in the last one sum_of_even().
And my suggestion corrects that.
Naumf wrote: And about the while loop, I use both of them, but I've included this one now.
But the one I referenced was not right.
Naumf wrote: Any help about the last function?
Other than what I already suggested?
If you will implement my suggestions, your code will work.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
The code you've referenced wasn't right because it needed additional coding...
And about the error, I found it, it was in q1 which wasn't needed at all. And about the declaration it is better to be before main() and it is correctly to be like you say, but it work in both ways . Thanks for your effort.
|
|
|
|
|
Naumf wrote: And about the error, I found it, it was in q1 which wasn't needed at all.
Neither was q .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
DavidCrow wrote: Neither was q.
I always thought that it's better to work only with p, because in some lists, i.e. singular linked list you don't count that value in the condition, but I don't know the correct coding for that, and this is the way like we are studying stupid but kinda useful xD
|
|
|
|
|
Hello people!
I know, nowadays noone is using DirectDraw anymore but i hope some of you still remember those times and can answer me a question. You can use the flag DDSCL_MULTITHREADED to make DD "multithread-aware". I supose this means that it enables the usage of critical sections or mutexes to add some synching. Now, my question is, is is possible to get access to this mutex or critical section to lock and release it manually?
Thanks in advance for any answers.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Hello, I hope that somebody can help me, the thing is this:
the context: my application has one main dialog and one non-main dialog.
the question: When I press a specific button in the non-main dialog, a line has to be drawn in the client area of the main dialog. how can I do this?
Actually I have a method declared as public and defined in the main dialog class (an instance from Cdialog let's say) to draw my lines, this is the method:
void CCalibracionDlg::BorrarRecta(int Rx,unsigned char D_Ry, unsigned char Vref)
{
CClientDC pDC(this) ;
float tgAng=0,Ry=0;
int x = 0 , y = 0 ,y_=0;
char multiplo=0;
unsigned char indice_recta=0, y_RectaVieja[300];
unsigned int pixel=0, PixelRectaVieja[300];
pDC.SetWindowOrg(-168,-165);
.
.a lot of code that it isn't important for this issue
.
}
Of course when i use this code within the main dialog it works fine, the lines are drawn in the client area of the main dialog, but how can i do to use this code to draw in the client area of the main dialog when i press a button in the non-man dialog? .
Thanks in advance, let me know if you need more information.
|
|
|
|
|
timbk wrote: when i use this code within the main dialog it works fine
There's your answer. If it works in the main dialog, then have the non-main dialog send a message to the main dialog when the button is pressed; the message handler in the main dialog will then draw the line.
|
|
|
|
|
Ok , thanks for your time, well I'm quite newbie programing, folowing your suggestion , the message that I use in the non-main's button is BN_CLICKED, and of course i have a method to handle this message, but , can you tell me how can i do to send a message to the main dialog from this message handler in the non-main dialog?
|
|
|
|
|
right now i am in a c++ class and even though the questions don't require validation i still lose points on my work i submit, i need to cover my bases here, can anyone help me find a way to reject alphanumeric values and accept only numeric ones?
thanks to anyone who can help.
|
|
|
|
|
You can check if a character is a digit either using the isdigit[^] function or by checking if its ASCII value is between 48 and 57.
|
|
|
|
|
thank you, this look easy to implement into my programs.
|
|
|
|
|
I am writing a multithreaded TCP server(MFC).
The steps I am following are:-
1.)Create a listen socket.
2.)listen on specific port.
3.)spin individual thread for every client that connects.
My application is a dialog based MFC App.But it crashes when a client connects to it.
While spinning the THREAD what parameter should I pass to the thread's main function(CDialog Object or listening socket).
what type of thread should I Create WORKER or UI.
My code is like this:-
BOOL CsockDlg::OnInitDialog()
{
.
.
.
int m_iPort = 4000;
m_sConnectSocket.SetParent(this);
m_sListenSocket.SetParent(this);
m_sListenSocket.Create(m_iPort);
m_sListenSocket.Listen();
return TRUE;
}
void CsockDlg::OnAccept(void)
{
AfxBeginThread(ThreadServer, this);
}
UINT CsockDlg::ThreadServer(LPVOID pParam)
{
CsockDlg* C = (CsockDlg*)pParam;
CAsyncSocket client;
C->m_sListenSocket.Accept(client);
return 0;
}
I have seen many examples for console servers but how to implement it on a Dialog Based Application?????
Future Lies in Present.
Manmohan Bishnoi
|
|
|
|
|
Manmohan29 wrote: My application is a dialog based MFC App.But it crashes when a client connects to it.Frown
While spinning the THREAD what parameter should I pass to the thread's main function(CDialog Object or listening socket).Confused
Hi again!
1) CAsyncSocket is event based and there is no need to use multithreading. This kind of networking model provides everything in a single thread context.
2) Did you try an example from the links I gave you a day ago? I would be much easier for us to help when you start from a working example.
3) What do you mean with "spinning a thread"?
Happy coding
/M
|
|
|
|
|
Thanks for the advice.
I was becoming a little bit lazy to search the examples(Today is Diwali[Indian Festival]). But now i will look them.
I meant "creating a thread for every client" for "spinning a thread".
Future Lies in Present.
Manmohan Bishnoi
|
|
|
|
|
This is the code for threaded server's accepting function
void AcceptConnections(SOCKET ListeningSocket)
{
sockaddr_in sinRemote;
int nAddrSize = sizeof(sinRemote);
while (1) {
SOCKET sd = accept(ListeningSocket, (sockaddr*)&sinRemote,
&nAddrSize);
if (sd != INVALID_SOCKET) {
cout << "Accepted connection from " <<
inet_ntoa(sinRemote.sin_addr) << ":" <<
ntohs(sinRemote.sin_port) << "." <<
endl;
DWORD nThreadID;
CreateThread(0, 0, EchoHandler, (void*)sd, 0, &nThreadID);
}
else {
cerr << WSAGetLastErrorMessage("accept() failed") <<
endl;
return;
}
}
}
we accepting the connection
SOCKET sd = accept(ListeningSocket, (sockaddr*)&sinRemote,
&nAddrSize);
and, then creating a thread to handle client
CreateThread(0, 0, EchoHandler, (void*)sd, 0, &nThreadID);
Here we are passing the connecting socket to the thread function.
And I am puzzled how to pass the connecting socket to thread's function in my application.
" Future Lies in Present. "
Manmohan Bishnoi
|
|
|
|
|
1. Your first post shows that you're using MFC. You could so use CAsyncSocket like the other poster suggested to you.
2. Creating a thread for each connection is inefficient, and can you imagine what would happen when the number of connections keep raising? If you would like to use threads to serve the client requests, just accept the connections in the UI thread and use a thread pool for the serving purpose.
3. Using CreateThread in an MFC program is an extremely bad idea. If you are using MFC, you *must* use AfxBeginThread to create a worker thread. (Generally there is no reason to call CreateThread at all. If you are not using MFC, you should still be calling _beginthreadex )
4. It looks like you are deriving a dialog class from a socket class? Can't a socket class be contained within your dialog class instead?
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Just a comment, Rajesh: The poster showed in his previous post that CsockDlg is a CDialog derived class. He tries to convert a multithreaded-socket-API example into an even-based-CAsyncSocket version, if I am not mistaken. Because those two networking models are very different, it's probably easier to start with a fresh working MFC example.
Cheers
/M
|
|
|
|
|
|
I'm glad you found something that'd be of use to you. Dr. Joseph is a terrific guy and his site is loaded with useful articles. On an additional note, he is supporting my view of using a thread pool: Even if the message that comes in from the socket requires considerable computing, the more effective method is to have all the sockets running in the main GUI thread, and have the extensive computing handled by threads from a thread pool.
Important: Never delete any of your messages that you post to this board. It is a RULE! Read the guidelines. I find a question has been posted to me and come here to reply, but I see that it has been removed.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
I didn't deleted my post intentionally. Just hit the Post Message Button in a hurry instead of preview.
Don't misunderstand me.
Future Lies in Present.
Manmohan Bishnoi
|
|
|
|
|
This isn't a simple example and the use of threads together with CAsyncSocket is unjustified and inefficient. Joseph M. Newcomer is a deeply respect member in developer circles, however I would say that the link you found was never intended as a MFC networking tutorial. Mixing asynchronous sockets and threads make little sense, here is an overview of basic server concepts:
a) blocking servers (handling only one request at a time, then wait again blocking)
b) threaded servers (handling simultaneous requests, one thread for every new socket, maybe from a pool).
c) asynchronous server (handling simultaneous requests, one thread context will handle all sockets)
d) variants such as IO completition ports
Instead of trying to convert one example code you had into a different thing, it would be easier if you learn about different networking concepts and start with simple examples. There are so many choices and CAsyncSocket might not be the best alternative in the long term (there are known problems). Perhaps have a look at some of the links I gave you.
/M
|
|
|
|
|
Language ID is a WORD from function GetSystemDefaultLangID().
I think there are existing user/system functions which can convert language ID to String, such as:
0x03 (SUBLANG_ARABIC_EGYPT) to string "Arabic (Egypt)"
so that I can save my time to redo them one by one.
Any hints/links?
Thanks
|
|
|
|