|
not insane yet! wrote: how can i merge the inputs in numA[] and numB[] and put them in the array of numAB[]?
I believe you should read about Merge Sort![^]
"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
|
|
|
|
|
Try this:
---------
#include <algorithm>
#include <iostream>
#include <iterator>
void Merge(const int (&a)[5], const int (&b)[5], int (&ab)[10])
{
std::merge(a, a+5, b, b+5, ab);
}
int main(int argc, char* argv[])
{
int a[] = {1, 3, 5, 7, 9};
int b[] = {2, 4, 6, 8, 9};
int c[10];
Merge(a, b, c);
std::copy(c, c+10, std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;
return 0;
}
Steve
|
|
|
|
|
Did you solve the problem?
Steve
|
|
|
|
|
I have a program that works just fine if I run it in Debug mode and set up a break point at a specific line. If i run it normaly it doesn't work, Beacuse it skips to fast that part of the program. Now here i am asking you, how can i stop the execution for let me say 3 seconds? Thanks
|
|
|
|
|
You can stop the program, but really you need to fix your design. Why is it 'too fast' ? You've not described what it does. If you want to stop for the user to read something, don't select an arbitrary time, show it in a message box that they can close whenever they want.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
The program reads a string from the COM port and then enters it in a database. Because the system reads the port to fast and then tryes to enter the string to the database, i only get the first char of the string in the database.
|
|
|
|
|
tanarnelinistit wrote: he program reads a string from the COM port and then enters it in a database.
hows your program read string from COM port... as you can read only a byte at time from comport!
"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 need to come up with a way to know that all the string has come through - is it null terminated ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
What is problem exactly ??
Are u getting the complete data through the port ??
Give us some more details..
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
Ok I'm using a code posted on this side under C++ serial class, I read from the port 16 bytes and i want to write them in the database, i got the string into the database but i seem to get some nasty results too. I should get smth like "FFFF00000000028C" but there are times when i get " FFF00000000028".
|
|
|
|
|
I think you could get more help if you were questioning your design instead of asking for a direct solution.
Anyway, concerning your original question, you can make a program slower by calling ::Sleep(milliseconds). If you wait for 10ms or 20ms you can check the port again to see if you received more data. To wait 3 seconds you would call ::Sleep(3000).
Under Windows 95/98/Me the smallest time that actually has a wait effect is 50ms, on NT/2K/XP you can use 10ms as the smallest wait time.
Anyway, it seems to me that a good design would be better than using ::Sleep() to solve a timing problem.
I hope this helps,
Rilhas
-- modified at 18:10 Friday 21st July, 2006
|
|
|
|
|
hi ,
Here is one trouble I met in my MDI program.
Worker thread is responsible for data collection from other source continuously. I defined one variable varData to contain the coming data. And notice main thread by customized message.
Main thread (CMainFrame/Views) is responsible to update the views to reflect the new value of varData.
I have used one critical section to control the writing to varData in worker thread. Yes. I have to do it. Here my concern is that whether it is necessary/must for me to use same critical section in views of MDI to control reading varData.
in My MDI, so many views are open, if CS is used ,I'm afraid the performance of my prgram will regress greatly.
pls Experts give your suggestion.
Appreciate for your help!
Sm
|
|
|
|
|
Yes it is. The CS will mean that only one thread can use the resource guarded by it. However, if the data structure is anything but an atomic data type there is the possibility of reading an incomplete (ie corrupt) update.
One way many applications avoid this is by having a queue of allocated changes. The writer gets the CS, allocs a change item, and appends to the queue, releases the CS, then signals a reader (shouldn't normally be more than one).
Reader gets the CS, pulls the queued item, and releases the CS. Uses the queued item to update a snapshot of the data, and deallocs the item. It then calls updateallviews (in MFC apps)
In your design, you are ensuring that the writing of data is serialised; in most cases, reading needs to be the same. I have seen a number of instances where all iterating over a collection needed to be guarded by a sync object as did all writes/erases; the original developer didn't understand that the collection was not thread safe in the sense that modifying while reading was a bad thing to do.
Steve S
Developer for hire
|
|
|
|
|
Hi,
My messagebox code snippet is like this
MessageBox( "Welcome", "title",MB_OK|MB_ICONINFORMATION);
How do i control the location of the message "welcome" in the messagebox? (if i want to move the word "welcome" to someother place, how do i do tat?). Can anyone please help me in this problem?
Thanks in Advance.
Regards,
Ram
|
|
|
|
|
Ram Murali wrote: ow do i control the location of the message "welcome" in the messagebox? (if i want to move the word "welcome" to someother place, how do i do tat?). Can anyone please help me in this problem?
use \n :- New Line
\t :- tab!
"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
|
|
|
|
|
I wannu control the location of the string in -x direction(move towards left side) not in y direction. sorry for the confusion.
Regards,
Ram
-- modified at 3:32 Friday 21st July, 2006
|
|
|
|
|
Ram Murali wrote: wannu control the location of the string in -x direction(move towards left side) not in y direction. sorry for the confusion.
For that you have to write your own custom MessageBox as quoted by NiceNaidu
"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 Re
|
|
|
|
|
|
How can i convert a value that is in char format: char news[16] to string? the simple sintax:
CString str2 = news;
str2.Format("%s");
doesn't seem to do it.
|
|
|
|
|
CString str2;
str2.Format("%s",news);
Will do this.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
|
y such a long link for this?????/
Dream bigger... Do bigger...Expect smaller
aji
|
|
|
|
|
Keeping view of Beginners, I posted that.Itz really good link for Beginners.
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
Its me wrote: y such a long link for this?????/
just a normal habit of programmer.... cut and paste
"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
|
|
|
|
|
tanarnelinistit wrote: CString str2 = news;
str2.Format("%s");
this will do too, call argument constructor of CString class
CString str2(news);
"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
|
|
|
|