|
could anyone plz tell me how can i intialized
unsigned short int test_array[256][256] to zero or empty
Thanks!
|
|
|
|
|
Brutal method:
for (int i = 0; i < 256; i++) {
for (int j = 0; j < 256; j++) {
test_array[i][j] = 0;
}
}
wiser one:
::memset(test_array, 0, sizeof(unsigned short int)*256*256);
[edit]
-- modified at 12:08 Thursday 15th February, 2007
Better one:
unsigned short int test_array[256][256] = {0};
thanks David
[/edit]
|
|
|
|
|
toxcct wrote: wiser one:
::memset(test_array, 0, sizeof(int)*256*256);
Which would actually not be very wise as an int is twice as large as an unsigned short .
memset(test_array, 0, sizeof(test_array));
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
i'm really confused, i read int at first, not unsigned short int
by the way, i prefer writing the explicit
sizeof(unsigned short int)*256*256 instead of
sizeof(test_array) because i find it more clear in the reader's mind.
of course, if the array change of type, my code must be adapted, not yours.
|
|
|
|
|
::memset(test_array, 0, sizeof(int)*256*256);
thanks but how can be done in C langauge.
|
|
|
|
|
firstly, check the code, it's been modified (with unsigned short int instead of int in the sizeof() )
secondly, the code is quite C. remove :: before the memset, and all the remaining is C code.
don't forget however to #include <stdlib.h>
|
|
|
|
|
unsigned short int test_array[256][256] = { 0 };
memset(test_array,0,sizeof(test_array)); If you need to clear the array sometime after it's definition.
Software Zen: delete this;
|
|
|
|
|
you didn't read the other posts in the thread, did you ?
here[^] is what i told David about this...
|
|
|
|
|
ikbahrian wrote: could anyone plz tell me how can i intialized
unsigned short int test_array[256][256] to zero or empty
Like:
unsigned short test_array[256][256] = {0};
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: unsigned short test_array[256][256] = {0};
does this set all the array cells to 0, or only the 1st one ? I have a doubt
|
|
|
|
|
toxcct wrote: does this set all the array cells to 0...
Yes, that's what the REP STOSD instruction is for.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
STOre String Doubleword.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
toxcct wrote: does this set all the array cells to 0, or only the 1st one ? I have a doubt
"If a class has a constructor, arrays of that class are initialized by a constructor. If there are
fewer items in the initializer list than elements in the array, the default constructor is used
for the remaining elements. If no default constructor is defined for the class, the initializer
list must be complete — that is, there must be one initializer for each element in the array."
But why doesn't this use the "default constructor" ...
unsigned short test;
Great job, team. Head back to base for debriefing and cocktails.
|
|
|
|
|
yes, but we have no class here, only native type
|
|
|
|
|
Right - check my post again (I just appended it )
I see the behavior but I'd like to see it documented. Anyone know where I can find that?
Mark
Great job, team. Head back to base for debriefing and cocktails.
|
|
|
|
|
toxcct wrote: does this set all the array cells to 0, or only the 1st one ? I have a doubt
It does set all array cells with 0, in this case. Actually, this is standard way to initialize array.
|
|
|
|
|
It sets the first element to 0 (because that's the value inside the braces). Then, since you're out of initializers, the remaining elements are automatically set to 0.
|
|
|
|
|
Hello!
Iam beginner of vc++, and trying small project in vc++ using MFC.
Plz can any one give me the guide lines for the project
Counting the number of pages the printer was printing .
This is my first message ,so if any mistake in the message
Plz avoid that.
Regards,
shakumar
shakumar
|
|
|
|
|
int i;
for (i = 0; I < nNbPagesToPrint; i++) {
std::cout << "Printing page " << (i+1) << std::endl;
PrintPage();
}
std::cout << "Nb Pages printed : " << i << std::endl;
|
|
|
|
|
You quanify cout with std but you don't for endl . I assume this is an oversight.
Steve
|
|
|
|
|
you're right, i fixed this...
anyway, i was joking, so it doesn't really matter, because i doubt one will compile this
|
|
|
|
|
shanthakumar_21 wrote: Plz can any one give me the guide lines for the project
Counting the number of pages the printer was printing .
Not exactly a project for a beginner, but you'll need to become familar with the Printing and Print Spooler API.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi everybody,
in my project i have a complicated/strange structure of architecture :
MDI Project -> Frame(1) -> View(2) -> TabWnd(3) -> View(4) -> TabWnd(5) -> View(6)
1) The Frame with all customers
2) A View which contains the TabWnd
3) Each Tab of the TabWnd corresponds to a Customer
4) The View which displayes the informations and a Tab
5) The Tab with several opened "orders from this customer"
6) The detail of the order
If i press the ESCAPE Key in the Order-View(6) i send a Message to the MainTab(3) which
should close the entire Tab (should close 4+5+6)
The "RemoveTab" Function performs a ->DestroyWindow() of the View in this Tab (4)
Now the question : Why does it calls the destructores in the different way?
At first Destructor of the View(6), than the destructor of the View(4) which performs a "delete Tab;" and follows the destructor of the Tab(5)
Is it possible that the View(6) destroyes automaticly all Views from which he is the owner?
Big thanks
|
|
|
|
|
A parent Window, when closed, automatically closes all of its child windows. Your structure as you describe it appears to be something like this:
Frame(1)
|
+- View(2)
|
+- TabWnd(3)
|
+- View(4)
|
+- TabWnd(5)
|
+- View(6) If the window and/or object destructions are happening out of order, it's possible you've got a parent/child connection (either in the windows or in the objects) that's not correct.
Software Zen: delete this;
|
|
|
|