|
If I were you, I would write a wrapper around your serial port (and most probably get rid of MSComm active X). This class would then store the data so that mutliple parts of your application can retrieve the required information.
|
|
|
|
|
#include <iostream.h>
int main()
{
int x=1,y;
y= ++x*++x;
cout << x << endl;
cout << y <<endl;
return 0;
}
|
|
|
|
|
Because you shouldn't use the pre-increment operator that way.
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]
|
|
|
|
|
Hello
It's not very hard. answer of this simple question is :
YOU WRITE ++x TWICE.y=++x[first time]*++x[second time]
don't forget to vote me.
BYE...
|
|
|
|
|
++x
*
++x
You should not use expressions like this as they may not give the results you expect.
It's time for a new signature.
|
|
|
|
|
Richard MacCutchan wrote: You should not use expressions like this as they may not give the results you expect.
I welcome you to take a look at our codebase.
Workout progress:
Current arm size: 14.4in
Desired arm size: 18in
Next Target: 15.4in by Dec 2010
Current training method: HIT
|
|
|
|
|
Note that priority of ++ operation is higher than *.If you have y= ++x*x++ it should be 4.
I would recommend you not to use such features because it makes code very hard to understand and modify.
Keep it simple and you will avoid getting in troubles.
Life is a stage and we are all actors!
|
|
|
|
|
Hristo Bojilov wrote: Keep it simple
I agree.
BTW: the exact order of the expression evaluation and the side-effects has been undefined in many languages for a long time. However IMO a compiler should issue a warning whenever you rely on assumptions, i.e. undefined results.
|
|
|
|
|
|
Hello all
this is my maze. when the worm reach to wall it passes the wall and sometime it stops.
#include <stdio.h>
#include <conio.h>
int dir=0;
char wall[40][50]={
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1},
{1,1,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,1},
{1,1,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,1},
{1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1},
{1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,1,0,1},
{1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1},
{1,1,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1,1,0,1},
{1,0,1,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1},
{1,1,1,1,1,1,1,1,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1},
{1,1,0,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1,0,1},
{1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1},
{1,1,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1,1,0,1},
{1,0,1,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
};
create_wall();
arrow_keys();
void main()
{
int a=3,b=2;
create_wall();
lbl : arrow_keys();
if (dir==72){
b-=1;
if (wall[a][b]==0){wall[a][b]='*';gotoxy(a,b); printf("%c",wall[a][b]);goto lbl;}
else b+=1;goto lbl;
}
if (dir==75){
a-=1;
if (wall[a][b]==0){wall[a][b]='*';gotoxy(a,b); printf("%c",wall[a][b]);goto lbl;}
else a+=1;goto lbl;
}
if (dir==77){
a+=1;
if (wall[a][b]==0){wall[a][b]='*';gotoxy(a,b); printf("%c",wall[a][b]);goto lbl;}
else a-=1;goto lbl;
}
if (dir==80){
b+=1;
if (wall[a][b]==0){wall[a][b]='*';gotoxy(a,b); printf("%c",wall[a][b]);goto lbl;}
else b-=1;goto lbl;
}
if (dir==0) {printf("exit");}
}
create_wall(){
clrscr();
int i,j;
for(i=0;i<15;i++){
for(j=0;j<26;j++){
if (wall[i][j]==1) printf("²");
else printf(" ");
}
printf("\n");
}
gotoxy(2,2);
printf("**");
}
int arrow_keys()
{
int ch;
while(1)
{
ch=getch();
if(ch==0)
{
ch=getch();
if(ch==72) {dir=72; break;}
if(ch==75) {dir=75; break;}
if(ch==77) {dir=77; break;}
if(ch==80) {dir=80; break;}
}
else dir=0;
break;
}
}
Where is the problem.
|
|
|
|
|
Here are a few ideas for you to make life easier in the future:
1. Don't use global variables when you don't have to. In your case, wall might be acceptable, but dir should not be global.
2. Don't confuse others by writing wall[40][50] and only initialize 15/26.
3. If wall is global, add globals for the wall bounds as well. You don't want to use hard coded values (like 15 and 26) anywhere else but very close to you wall definition. (you can't trust sizeof() operator either the way you have done it)
4. Be consistent in your naming. Don't use indexes a and b in one place, and i and j in another for the same thing. x and y would do just fine.
5. Do not use labels and goto where a simple loop will be enough. Your code will be hard to follow and maintain, even if it's correct. If you need a label, and it will be a long time before you do, give it a meaningful name.
6. Let arrow_keys return its value instead of changing a global variable. It's defined to return an int, but never does. So is also create_wall() by the way.
7. Use constant identifiers instead of hard coded numbers. An enum type is well suited for your direction variable. Again, think of naming.
8. printf("%c", ...)? Have a look at putc().
9. Indentation looks a bit random, and so does placement of curly brackets. Adopt a consistent style.
That said, finding these kinds of bugs is an easy job if you step through the code in a debugger, inspecting indexes into your wall matrix.
But clean up your code first.
|
|
|
|
|
Hello all
I am working on maze in turbo c(command prompt not windows). I write 90% of it.
but there are 2 problems I do any work can't solve it.
1- When worm(** is my worm) reach a wall it don't stop. it can pass the wall?
2- the worm make longer but it should be ** in any time?
#include <stdio.h>
#include <conio.h>
int dir=0;
char wall[40][50]={
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,1,1,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1},
{1,1,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,1},
{1,1,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,1},
{1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1},
{1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,1,0,1},
{1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1},
{1,1,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1,1,0,1},
{1,0,1,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1},
{1,1,1,1,1,1,1,1,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1},
{1,1,0,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1,0,1},
{1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1},
{1,1,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1,1,0,1},
{1,0,1,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
};
create_wall();
arrow_keys();
void main()
{
int a=3,b=2;
create_wall();
lbl : arrow_keys();
if (dir==72){b-=1; wall[a][b]='*';gotoxy(a,b); printf("%c",wall[a][b]);goto lbl;}
if (dir==75){a-=1; wall[a][b]='*';gotoxy(a,b); printf("%c",wall[a][b]);goto lbl;}
if (dir==77){a+=1; wall[a][b]='*';gotoxy(a,b); printf("%c",wall[a][b]);goto lbl;}
if (dir==80){b+=1; wall[a][b]='*';gotoxy(a,b); printf("%c",wall[a][b]);goto lbl;}
if (dir==0) {printf("exit");}
}
create_wall(){
clrscr();
int i,j;
for(i=0;i<15;i++){
for(j=0;j<26;j++){
if (wall[i][j]==1) printf("²");
else printf(" ");
}
printf("\n");
}
gotoxy(2,2);
printf("**");
}
int arrow_keys()
{
int ch;
while(1)
{
ch=getch();
if(ch==0)
{
ch=getch();
if(ch==72) {dir=72; break;}
if(ch==75) {dir=75; break;}
if(ch==77) {dir=77; break;}
if(ch==80) {dir=80; break;}
}
else dir=0;
break;
}
}
Please help me to solve the problems.
Thanks in advance
|
|
|
|
|
|
You're not erasing where the "worm" is when you draw the new one on the screen and you're not testing where the new worm head is and ending the game (if that's the rule) when the worms head hits a wall. To get round these problems:
- You can deal with the extra drawing by overwriting the worm's current position with spaces after you poll the keyboard but before you change the position of the worm.
- When you change the worm's position do a check to see if the new position overwrites a 1 in your maze. If it does, end the game.
Cheers,
Ash
|
|
|
|
|
Hello Ash;
I wrote these codes you say me. but it doesn't work correctly. It stop in another position that there is no wall and sometime it pass a wall and stop on the next one.
These code are right, but I can't write them in its own place.
Please help me by writing codes if it is possible for you.
|
|
|
|
|
I'm trying to write a bho to get the ocx in IE. I'm a newer to bho. I'm not famailar with com. I really need your help. Please, help me, and I will really appreciate your help!
|
|
|
|
|
Already posted in COM forum.
It's time for a new signature.
|
|
|
|
|
Hi,
i'm using WMI to get some Parameters of the local Computer.
Here is a Sample Code Snippet:
<code>
pEnumerator = NULL;
hres = pSvc
->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_BIOS"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
*pclsObj;
uReturn = 0;
while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);
if(0 == uReturn)
{
break;
}
VARIANT vtprop;
hr = pclsObj->Get(L"SerialNumber", 0, &vtprop, 0, 0);
wcout << vtprop.bstrVal << endl;
VariantClear(&vtprop);
pclsObj->Release();
}
</code>
This works very well.
How must i change this, to show the IP-Adressses of the Computer? Only with Changing to "Win32_NetworkAdapterConfiguration" and "IPAddress" instead of "SerialNumber" doesn't works.
I think, because IPAdress is an Array in WMI?
modified on Saturday, June 19, 2010 12:50 PM
|
|
|
|
|
Go over to Microsoft and download: WMI CIM Studio. With it you can search the entire WMI on your local machine.
But, and I'm trying to remember, I think the IP address is written to the Registry when you connect to a Wireless network. I'd have to look it up. Get back tp you.
|
|
|
|
|
Sorry but this is not the solution for my Problem. I need help with my C++-Code above. That's why i have asked in this forum and not anywhere else
|
|
|
|
|
|
Hi,
it is a bit more complex than you seem to expect. You need Win32_NetworkAdapterConfiguration . It will return several rows, some have IPEnabled set to true; those should correspond to physical network adapters, which each can have one or more IP addresses; these are returned as a string array through IPAddress .
A little Google action should turn up sample code in the language of your choice.
|
|
|
|
|
Marcel Vogt wrote: How must i change this, to show the IP-Adressses of the Computer? Only with Changing to "Win32_NetworkAdapterConfiguration" and "IPAddress" instead of "SerialNumber" doesn't works.
I believe that using WMI is the easier but not the best option to work with IP addresses.You have entire IP helper API right here http://msdn.microsoft.com/en-us/library/aa366071(VS.85).aspx[^] which contains set of functions for IP management.For example GetIpAddrTable function will help you to examine IP-v4 mapping table.
Life is a stage and we are all actors!
|
|
|
|
|
Hey folks!
I was just wondering, which of these would be faster:
RECT R1, R2;
POINT Offset;
...
R1 = R2;
R1.left += Offset.x;
R1.right += Offset.x;
R1.top += Offset.y;
R1.bottom += Offset.y;
or
RECT R1, R2;
POINT Offset;
...
R1.left = R2.left + Offset.x;
R1.right = R2.right + Offset.x;
R1.top = R2.top + Offset.y;
R1.bottom = R2.bottom + Offset.y;
As a "sub question of this", would this:
R1.left += Offset.x;
R1.right += Offset.x;
R1.top += Offset.y;
R1.bottom += Offset.y;
be faster than this:
R1.left += Offset.x;
R1.top += Offset.y;
R1.right += Offset.x;
R1.bottom += Offset.y;
? I mean, in the first version when the first addition is done Offset.x is already loaded into one of the registers so the second addition needs less memory access, while in the second version, it would need to retrieve Offset.y to do the addition, then retrieve Offset.x again and then Offset.y again. In the first version it has to retrieve both Offset.x and Offset.y only once during the 4 additions, so that's half the memory access from Offset's point of view. Right? If so, I also wonder if the compiler is smart enough to change the order of these to produce a more speed optimized code (i personally highly doubt this).
Thanks for any sharing of thoughts.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Computers don't kill programs, users kill programs <
> "It doesn't work, fix it" does not qualify as a bug report. <
|
|
|
|
|
The only way to find out is to write some tests, compile and run them on your system. Arguing thoretically about what's faster is fairly pointless.
Cheers,
Ash
|
|
|
|
|