|
<br />
while ((ch = getchar()) !=EOF && isdigit(ch)){<br />
result = result *10 + ch - '0';<br />
}<br />
printf("number is %d\n", result);<br />
i wonder what is '0' means. Is it is null character?
~~~@@@###EZRA###@@@~~~
|
|
|
|
|
EzraYap wrote: result = result *10 + ch - '0';
actually it's not null.. actually it is ascii based calculation.. i.e. '0' ascii value is 41 , '1' will 42 and so on.. so it way of extracting number from char character ... thats logic here
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief And you
|
|
|
|
|
Thanks. i undestand now.
~~~@@@###EZRA###@@@~~~
|
|
|
|
|
ThatsAlok wrote: thats logic here
The only logical thing to say would be arithmetic
--
Presented in doublevision (where drunk)
|
|
|
|
|
Jörgen Sigvardsson wrote:
The only logical thing to say would be arithmetic
he he he
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief And you
|
|
|
|
|
Hi All.
I start to learn multiThread and i wrote some simple program.
I dont know why i crash - i try to look into by using debug and i dont see nothing wrong.
IF someone can tell me what i doing in wrong way .... ?
Thanks for any help.
Here the code :
<br />
...<br />
...<br />
<br />
using namespace std;<br />
<br />
CRITICAL_SECTION sc;<br />
<br />
void __stdcall func(LPVOID param)<br />
{<br />
char szBuffer[256];<br />
{<br />
EnterCriticalSection(&sc);<br />
long lVal = *((long*)param);<br />
<br />
<br />
while(lVal > 0)<br />
{<br />
sprintf(szBuffer, "lVal is : %ld \n", lVal--);<br />
printf(szBuffer);<br />
}<br />
LeaveCriticalSection(&sc);<br />
}<br />
}<br />
<br />
<br />
void main(void)<br />
{<br />
HANDLE thread1,thread2;<br />
<br />
long lVal = 10;<br />
<br />
thread1 = CreateThread(NULL,<br />
5,<br />
(LPTHREAD_START_ROUTINE)func,<br />
&lVal,<br />
CREATE_SUSPENDED,<br />
NULL);<br />
<br />
SetThreadPriority(thread1, THREAD_PRIORITY_HIGHEST);<br />
<br />
lVal = 1000;<br />
<br />
thread2 = CreateThread(NULL,<br />
5,<br />
(LPTHREAD_START_ROUTINE)func,<br />
&lVal,<br />
CREATE_SUSPENDED,<br />
NULL);<br />
<br />
SetThreadPriority(thread2, THREAD_PRIORITY_HIGHEST);<br />
<br />
ResumeThread(thread2);<br />
ResumeThread(thread1);<br />
<br />
WaitForSingleObject(thread2, INFINITE);<br />
WaitForSingleObject(thread1, INFINITE);<br />
}<br />
|
|
|
|
|
maybe you have a deadlock, plz check ur algorithm before u check ur code..
And ever has it been that love knows not its own depth until the hour of separation
|
|
|
|
|
I don't have deadlock. and the algorithm is fine.
In case deadlock the application will not crash -
If i init the critical section ( in first line of the main i do InitializeCriticalSection(&sc); ) then i avoid the crash but i still see that the second thread get into the critical area even that the first thread is in it.
What wrong in the code ?
|
|
|
|
|
I realy need some help here.
|
|
|
|
|
It seems your problem is EnterCriticalSection
|
|
|
|
|
You missed this one buddy :
InitializeCriticalSection(&cs);
Dont you need to initialize it before you could enter into it?
Add it here:
<br />
char szBuffer[256];<br />
{<br />
InitializeCriticalSection(&cs)------->Here<br />
EnterCriticalSection(&sc);<br />
long lVal = *((long*)param);<br />
Good Luck
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
First of all ... the init of he critical section is need to be in the main and not in the function ( i dont want each of the thread the init it each time it start to run).
Second ... even if i call init in the main i have problem to run the second thread ( its just dont run ).
|
|
|
|
|
Oops didn't read the program fully.CS should be initialized once. Try this.
<br />
#include <conio.h><br />
<br />
using namespace std;<br />
<br />
CRITICAL_SECTION sc;<br />
<br />
void __stdcall func(LPVOID param)<br />
{<br />
AfxMessageBox("in thread");<br />
char szBuffer[256];<br />
long lVal = (*(long*)param);<br />
EnterCriticalSection(&sc);<br />
<br />
CString cs;<br />
cs.Format("%d",lVal);<br />
AfxMessageBox(cs);<br />
<br />
int testVal=lVal;<br />
while(lVal > 0)<br />
{<br />
sprintf(szBuffer, "I'm %d lVal is : %ld \n",testVal,lVal--);<br />
printf(szBuffer);<br />
}<br />
<br />
LeaveCriticalSection(&sc);<br />
AfxMessageBox("done"); <br />
}<br />
<br />
<br />
void main(void)<br />
{<br />
HANDLE thread1,thread2;<br />
<br />
long lVal = 5000;
InitializeCriticalSection(&sc);<br />
thread1 = CreateThread(NULL,5,(LPTHREAD_START_ROUTINE)func,&lVal,CREATE_SUSPENDED,NULL);<br />
<br />
<br />
SetThreadPriority(thread1, THREAD_PRIORITY_HIGHEST);<br />
<br />
long lVal2 = 1000;
<br />
thread2 = CreateThread(NULL,5,(LPTHREAD_START_ROUTINE)func,&lVal2,CREATE_SUSPENDED,NULL);<br />
<br />
SetThreadPriority(thread2, THREAD_PRIORITY_HIGHEST);<br />
<br />
ResumeThread(thread1); Sleep(3000);
ResumeThread(thread2);<br />
<br />
WaitForSingleObject(thread2, 500);
WaitForSingleObject(thread1, 500);
while(getch()!=27);
}<br />
Just did this one for test. Try it and tell me if it's useful or not. It's too late here .. see u tomorrow.. goodnight
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
Hi all,
I have a CListCtrl object in my programme. I want to unload or destroy it programmatically. How it is possible.
Please Help me,
Thanks in advance
George
|
|
|
|
|
georgekjolly wrote: have a CListCtrl object in my programme. I want to unload or destroy it programmatically. How it is possible.
have you created that programmatically?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief And you
|
|
|
|
|
CListCtrl* pCtrl;
pCtrl->DestroyWindow();
delete pCtrl;
--
Touch eyeballs to screen for cheap laser surgery
|
|
|
|
|
Jörgen Sigvardsson wrote: CListCtrl* pCtrl;
pCtrl->DestroyWindow();
delete pCtrl;
problem if it created statically!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief And you
|
|
|
|
|
Then you'll just need to call DestroyWindow(). The CListCtrl object is so small, that it doesn't matter much. We're talking 4-8 bytes.
|
|
|
|
|
Jörgen Sigvardsson wrote:
Then you'll just need to call DestroyWindow(). The CListCtrl object is so small, that it doesn't matter much. We're talking 4-8 bytes.
let have a try..
int i=10;
int *ptr=&i;
delete ptr; // program will crash here
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief And you
|
|
|
|
|
What does that have to do with anything? What I'm saying is that if you have a statically allocated object such as CListCtrl m_list , then that object will occupy around 4 to 8 bytes of memory (window handle + vtable). If you kill the window, which the object is a handle for, then 4 to 8 bytes is what'll be left.
DestroyWindow != delete
--
Nominated For Three Glemmys
|
|
|
|
|
Jörgen Sigvardsson wrote: DestroyWindow != delete
he he i got confused with delete operator=delete ...
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief And you
|
|
|
|
|
|
If you had meant to clear the content, m_List->ResetContent()
If you had meant to close it, m_List->CloseWindow()
If you had meant to destroy it, m_List->DestroyWindow()
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
it is pisibile to hide the CListCtrl ?
Bravoone
|
|
|
|
|
Yup, m_list->ShowWindow(false);
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|