|
Thanks, but as you expected I have no arguments specified there !
|
|
|
|
|
First of all, sorry for my bad english.. I need help with my c code..
void Calculate()
{
for (int i=0;i<1;i++)
{
for(int j=0;j<3;j++)
{
c[i][j] = x[i][j] * w[i][j];
sum1 += c[i][j];
printf("Output[%d]: %.1f ",i+1,c[i][j]);
}
printf("\n");
printf("Sum: %.1f\n",sum1);
}
printf("\n");
for (int i=1;i<2;i++)
{
for(int j=0;j<3;j++)
{
c[i][j] = x[i][j] * w[i][j];
sum2 += c[i][j];
printf("Output[%d]: %.1f ",i+1,c[i][j]);
}
printf("\n");
printf("Sum: %.1f\n",sum2);
}
printf("\n");
for (int i=2;i<3;i++)
{
for(int j=0;j<3;j++)
{
c[i][j] = x[i][j] * w[i][j];
sum3 += c[i][j];
printf("Output[%d]: %.1f ",i+1,c[i][j]);
}
printf("\n");
printf("Sum: %.1f\n",sum3);
}
printf("\n");
for (int i=3;i<4;i++)
{
for(int j=0;j<3;j++)
{
c[i][j] = x[i][j] * w[i][j];
sum4 += c[i][j];
printf("Output[%d]: %.1f ",i+1,c[i][j]);
}
printf("\n");
printf("Sum: %.1f\n",sum4);
}
printf("\n");
}
how can i make this code become simple? its a sum of each row.. it has 4 row, sum1 is the sum for the first row only.. and sum2 is the sum for the second row only and so on.. please help me on how to make this code simpler cause i think its redundant.. thanx..
|
|
|
|
|
Hi,
not sure since you didn't show all declarations, but this should come close:
int sums[4];
for (int i=0; i<4; i++) {
sums[i]=0;
for(int j=0; j<3; j++) {
c[i][j] = x[i][j] * w[i][j];
sums[i] += c[i][j];
printf("Output[%d]: %.1f ",i+1,c[i][j]);
}
printf("\n");
printf("Sum: %.1f\n",sums[i]);
}
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
thanx Luc Pattyn for ur help..
|
|
|
|
|
Hi all,
i am using this smart pointer to send http request to server:-
IServerXMLHTTPRequest2Ptr pIXMLHTTPRequest = NULL;
Then through this I called the method setproxy where second parameter is having some ip address:-
pIXMLHTTPRequest->setProxy(SXH_PROXY_SET_DIRECT,varProxyName,L"");
but this is causing exception and getlasterror() is returning "3".Please rovide some suggestions.
Thanks A Ton
Ash_VCPP
walking over water is just knowing where the stones are.....
|
|
|
|
|
When you call setProxy() have you already acquired a pointer to an object implementing the IServerXMLHTTPRequest2 interface? Have you properly set up varProxyName?
1300 calories of pure beef goodness can't be wrong!
|
|
|
|
|
Hi Bacon,
First of all thanks for the reply....i have posted it three times but i get first reply so thanks.
i have used pointer of the interface like this:
IServerXMLHTTPRequest2Ptr pIXMLHTTPRequest = NULL;
and called the method setproxy on the same:-
pIXMLHTTPRequest->setProxy(SXH_PROXY_SET_PROXY,varProxyName);
where varProxyName = SysAllocString(L"114.127.246.36:8080");
when you sya...."have you already acquired a pointer to an object implementing the IServerXMLHTTPRequest2 interface"
so can you explain it in detail.or if you can provide some example for set proxy then it would be really helpful, because i didnt get anything useful in google....
Thanks A Ton
Ash_VCPP
walking over water is just knowing where the stones are.....
|
|
|
|
|
Ash_VCPP wrote:
IServerXMLHTTPRequest2Ptr pIXMLHTTPRequest = NULL;
When you assign NULL to pIXMLHTTPRequest this tells it to point to nothing. You have to get an object of type IServerXMLHTTPRequest2 and assign it to pIXMLHTTPRequest before you can use it.
Ash_VCPP wrote: so can you explain it in detail.or if you can provide some example for set proxy then it would be really helpful, because i didnt get anything useful in google....
I haven't used IServerXMLHTTPRequest but it's a COM based object so you'll need to call CoCreateInstance() at some point. If you're not familiar with COM I suggest reading one of the introductions here on CP.
1300 calories of pure beef goodness can't be wrong!
|
|
|
|
|
hi Bacon,
Please see the code:
HRESULT hresult = CoInitialize(NULL);
IServerXMLHTTPRequest2Ptr pIXMLHTTPRequest = NULL;
hr=pIXMLHTTPRequest.CreateInstance("Msxml2.ServerXMLHTTP.4.0");
that i have done.....please suggest if i am missing something.
Thanks A Ton
Ash_VCPP
walking over water is just knowing where the stones are.....
|
|
|
|
|
Hello,
i tried it the way you said, but it did not work , maybe i did something wrong, hier is the code:
void CTestView::ThreadStart(CTestDoc* pDoc, CString strSel)
{
m_Thread_Sel_Start.SetEvent ();
HWND hWnd = GetSafeHwnd();
m_strSelect = strSel;
m_pDoc = pDoc;// i need to access the CTestDoc.cpp, i passed pDoc from the CTestDoc.cpp to the CTestView.cpp
// and then assigend pDoc to m_pDoc which defined in the top of the CTestView.cpp
AfxBeginThread(ThreadProc, this/*hWnd*/, THREAD_PRIORITY_NORMAL);// Hier i passed this to the ThreadProc function
}
UINT ThreadProc
(
LPVOID param
)
{
(CTestView*)param-> // casting to CTestView did not work?
return 0;
}
|
|
|
|
|
I encourage you to read this [^].
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]
|
|
|
|
|
okoay but i have an application crash hier:
#ifdef _DEBUG
void CTestView::AssertValid() const
{
CView::AssertValid(); // application crash
}
#ifndef _WIN32_WCE
void CTestView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif
#endif
|
|
|
|
|
You shouldn't use GUI stuff in worker threads.
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]
|
|
|
|
|
Is there a question here that I'm failing to see?
"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 question is when i pass (this) instead of (hwnd) to the ThreadProc function i get a crash. The question is above.
|
|
|
|
|
How about formatting your code correctly AND using the <pre> tag?
"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
|
|
|
|
|
-> has higher precedence than a cast, you need parens around the cast so it's evaluated first:
((CTestView*) param)->SomeMethod();
--Mike--
Dunder-Mifflin, this is Pam.
|
|
|
|
|
HI all,
I am working on Non Overlapped serial I/O application.
I have only one thread to receive the data.For send i dont have any thread.
I just call Write file when i need to send .
My problem is, When I have my receive thread wait for an event using WaitCommEvent, it ties up the serial port. Then my sending function can't access the port with WriteFile. I knew waiting for a comm event would block the receiving thread but didn't expect that it would block use of the port.
Any suggestions on how to do non-overlapped communication, where the send fucntion can write while the receive thread waits for a comm event?
Regards,
Sunil Kumar
|
|
|
|
|
Try to open the port twice using CreateFile .
Use one handle for writing and another for reading from the port.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
I dont think I can use CreateFile twice.
It is unable to create the second time.The handle is getting some undefined value,
when it is opened the second time.
Regards,
Sunil Kumar
|
|
|
|
|
You should be able to open more than once if you specify the FILE_SHARE_READ and FILE_SHARE_WRITE flags.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
«_Superman_» wrote: You should be able to open more than once if you specify the FILE_SHARE_READ and FILE_SHARE_WRITE flags.
You cannot do that with a communication resource (MSDN [^])
The CreateFile function can create a handle to a communications resource, such as the serial port COM1. For communications resources, the dwCreationDisposition parameter must be OPEN_EXISTING, the dwShareMode parameter must be zero (exclusive access), and the hTemplateFile parameter must be NULL. Read, write, or read/write access can be specified, and the handle can be opened for overlapped I/O.
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]
|
|
|
|
|
yeah, I am unable to open it twice even if I mention the shared attributes.
There is no other option for non overlapped I/O, if I have to WriteFile, when
my receive thread wait for an event using WaitCommEvent?
Regards,
Sunil Kumar
|
|
|
|
|
As workaround, you may use the same thread for both I/O.
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]
|
|
|
|
|
Even If I have to send data in the same receive thread,
I am unable to do as WaitCommEvent never returns.
My code block is:
if (!SetCommMask( pc->hCommn, EV_RXCHAR))
{
}
for ( ; ; )
{
if (WaitCommEvent(pc->hCommn, &dwCommEvent, NULL))
{
do
{
if (ReadFile(pc->hCommn, &chRead, 1, &dwRead, NULL))
{
pc->CopyRx(chRead);
}
else
{
break;
}
}while(dwRead);
}
else
break;
}
Where can I call my send fucntion in this thread, if I have some data to send.
Please suggest.
Regards,
Sunil Kumar
|
|
|
|