|
adepumadhu1 wrote: g_hDrawChartThread = CreateThread(NULL,0,DrawChart,pView,0,0);
Are you calling this function 10 times per second?
"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 program is to keep records and perform statistical for a class of students.
the class may have up to 40 students. They have 5 quizzes, and all the students are identified by a 4 digit student number
and the program will print the students scores and calculate and print the statistics for each quiz
Student Quiz 1 Quiz 2 Quiz 3 Quiz 4 Quiz 5
1234 78 83 87 91 86
2134 67 77 84 82 79
3124 77 89 93 87 71
High Score 78 89 93 91 86
Low Score 67 77 84 82 71
Average 73.4 83.0 88.2 86.6 78.6
but this is what i have so far
#include<stdio.h>
#define ROW 4
#define COLS 5
int main(void)
{
// Local Declarations
int table [ROW] [COLS] =
{
{1234,52,7,100,78,34}'
{2134,90,36,90,77,30},
{3124,100,45,20,90,70},
{4532,11,17,81,32,77}
};
int line [ROW * COLS];
// Statments
for (int row = 0; row <ROWS;row++)
for (int column =0; column < cols, column++)
line[row * cols + column] = table [row] [column];
for (int row = 0; row <ROWS * cols; row++)
printf("%02d", line [row]);
return 0;
} // main
please help
modified on Thursday, April 30, 2009 1:56 AM
|
|
|
|
|
I don't want to reveal my age, but the last time I did a homework was 10 years ago.
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
Okay
and thanks for nothing
|
|
|
|
|
biggiant22000 wrote: please help
With what?
|
|
|
|
|
biggiant22000 wrote: #define COLS 5
There are 6 "columns" in the table array.
biggiant22000 wrote: int line [ROW * COLS];
This variable is not necessary.
biggiant22000 wrote: {1234,52,7,100,78,34}'
...
for (int row = 0; row < ROWS;row++)
for (int column =0; column < cols, column++)
line[row * cols + column] = table [row] [column];
How do these even compile?
With a little bit of coercion , your code could produce something like:
Student Quiz 1 Quiz 2 Quiz 3 Quiz 4 Quiz 5
------- ------ ------ ------ ------ ------
1234 52 7 100 78 34
2134 90 36 90 77 30
3124 100 45 20 90 70
4532 11 17 81 32 77
High Score 100 45 100 90 77
"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
|
|
|
|
|
Im still not understand im getting 42 errors
|
|
|
|
|
biggiant22000 wrote: Im still not understand
Which part?
biggiant22000 wrote: im getting 42 errors
Start with the first one.
"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
|
|
|
|
|
Hi all,
I am having a c++ file which is used to create mexfunction DLL that can be used to call a function from Matlab through dll. This is used to compute some mathematical calculations on a big matirx and for this I do it in two parallel threads each doing half matrix. At the end I combine both to generate full resultant matrix. For this, I create two different threads as follows-
HANDLE thd_handle[2];
DWORD WINAPI GenerateThread0(LPVOID param);
DWORD WINAPI GenerateThread1(LPVOID param);
void CreateResult0();
void CreateResult1();
void mexFunction(...mex function params....)
{
thd_handle[0] = CreateThread(NULL,GenerateThread0, NULL, 0, NULL);
thd_handle[1] = CreateThread(NULL,GenerateThread1, NULL, 0, NULL);
WaitForMultipleObjects(2,thd_handle,true,INFINITE);
}
DWORD WINAPI GenerateThread0(LPVOID param)
{
CreateResult0();
return 0;
}
DWORD WINAPI GenerateThread1(LPVOID param)
{
CreateResult1();
return 0;
}
void CreateResult0()
{
}
void CreateResult1()
{
}
Everything is fine and good while doing as above and I used this for a long time without any problems. Now I am planning to make this more efficient by making it multithreading adaptable to the processor on which it runs. I have couple of systems which are like 4core/8core and would like to create threads dynamically. I came up with the following idea and implemented it and guess what it gives fatal errors while running and I highly suspect the way I am creating multiple threads.
HANDLE *thd_handle;
DWORD WINAPI GenerateThread(LPVOID param);
void CreateResult(unsigned int idx);
void mexFunction(...mexfunctionparams...)
{
thd_handle = new HANDLE[m_nThreads-1];
for (unsigned int i=0; i < m_nThreads-1; i++ )
thd_handle[i] = CreateThread(NULL, GenerateThread, &i, 0, NULL);
WaitForMultipleObjects(m_nThreads-1,thd_handle, true,infinite);
}
DWORD WINAPI GenerateThread(LPVOID param)
{
DWORD iter = *(DWORD*)param;
CreateResult(iter);
retrun 0;
}
void CreateResult(unsigned int idx)
{
}
if I use the dll generated from this code, the program crashes... am I doing something fundamentally wrong here?? is there any other better way to achieve this??
thanks for any help,
PKNT
|
|
|
|
|
Have you run it in a debugger (that's easy enough to do - just specify Matlab as the target executable) so you can see where the exception occurs?
Some things that do jump out at me:
- As it says in the CreateThread[^] documentation,
A thread in an executable that calls the C run-time library (CRT) should use the _beginthreadex and _endthreadex functions for thread management rather than CreateThread and ExitThread; this requires the use of the multi-threaded version of the CRT. If a thread created using CreateThread calls the CRT, the CRT may terminate the process in low-memory conditions. - You pass a pointer to a stack variable in the CreateThread call. That's not a great idea - you can't guarantee that the newly created thread will assign to iter before i changes. Why not just pass the value of i rather than the address. Even though the param is an LPVOID, integer is convertible to LPVOID and vice versa.
One other thing - why use m_nThreads-1 all over the place - once your main thread enters WaitForMultipleObjects, there will be m_nThreads cores available for processing, as the WaitForMultipleObjects call will yield the core it's on.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks for the reply... will try VC++ specific thread functions and see how it does and also the parameters thing.
Stuart Dootson wrote: One other thing - why use m_nThreads-1 all over the place - once your main thread enters WaitForMultipleObjects, there will be m_nThreads cores available for processing, as the WaitForMultipleObjects call will yield the core it's on.
this is for the system to be responsive for other applications/tasks that are running at the same time. I am leaving a core for this purpose.
thanks
PKNT
|
|
|
|
|
Kiran Satish wrote: this is for the system to be responsive for other applications/tasks that are running at the same time. I am leaving a core for this purpose.
That shows remarkable restraint
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I figured out the problem... nothing from the way I am assigning threads (but now I am using _beginthread/_endthread functions though), but an overseen logic mistake and improper reading of 2D matrices from a 3D matrix generated using OptiVec library. Now everything works fine. Thanks for your time.
PKNT
|
|
|
|
|
Kiran Satish wrote: nothing from the way I am assigning threads (but now I am using _beginthread/_endthread functions though), but an overseen logic mistake and improper reading of 2D matrices from a 3D matrix generated using OptiVec library
Doh!
Kiran Satish wrote: Now everything works fine
Good
Kiran Satish wrote: Thanks for your time
My pleasure
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I was looking for a "i++" somewhere
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Sorry, I do have i++ in there...
PKNT
|
|
|
|
|
i didnt see it here: for (unsigned int i=0; i < m_nThreads-1; )
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Well in the original program I have it, its a typo in y post and didn't had time to correct it in the morning when I replied to your reply.
PKNT
|
|
|
|
|
for (unsigned int i=0; i < m_nThreads-1; i++ )
thd_handle[i] = CreateThread(NULL, GenerateThread, &i, 0, NULL);
The problem is that you are taking the address of i and passing it to the thread function. However, by the time the thread function is able to start, i has likely changed and is probably invalid.
Since all you need is the actual value, just pass i (by casting it to LPVOID), and then in the thread function just pass param to CreateResult by casting it to a DWORD.
(I also don't understand why you keep subtracting one from your thread count. Why not just use the correct number to begin with?)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi All,
I wonder how can I make a combobox without using MFC. Can someone give me a clue about that.
Thanks a lot
|
|
|
|
|
HWND hCombo = ::CreateWindow( _T("ComboBox"), _T("Some Name") , WS_VISIBLE|WS_CHILD|CBS_DROPDOWNLIST, 0,0, 300, 300, hParent, 0, hInstance,0 );
Where hParent is the parent window handle and hInstance is the instance handle of the application/module.
|
|
|
|
|
Hi,
I have a CTreeCtrl in an application. When I click on an item, I want to do a particuliar action. To do that, I have to know the number of the item in the tree: first, second, third an so on.
How can I retreive that information ?
Thanks,
Claude
|
|
|
|
|
Are tree controls supposed to be viewed that way. What happens to items 2..N when item 1 is expanded? Does item 2 become item 3, etc?
I would opt for using SetItemData() for each item/node in the tree.
"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
|
|
|
|
|
Gagnon Claude wrote: To do that, I have to know the number of the item in the tree: first, second, third an so on
Number in the tree....how are you counting? Breadth first? Depth first?
And why do you need that - are you sure there's no other way of achieveing your objective?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: how are you counting?
See there's this roulette wheel and
|
|
|
|
|