|
this is only a part of the code the problem wit this code is that when then chagne is store in the bugger it always change example((bugger)6.7 = (change)6.6) it always change to a diferant number so can please tell me why please
|
|
|
|
|
You get this problem because of the way floating point numbers are represented, and the way types are converted.
When you convert a float to an integer, for example in the statement:
bugger = (float)change * (float)100;
the float is truncated (i.e. the fractional part is discarded.)
When you multiply two floats (eg 0.67 by 100.0), the answer will not be exactly an integer (eg. 67) - it will be slightly more or slightly less. Since the result you get after truncating is 66, this implies the float representation is less than 67, i.e. 66.9999 . . . Truncating 66.99999 gives 66.
The solution - add some small number to the result before truncating, as below
bugger = (float)change * (float)100 + 0.0001;
|
|
|
|
|
|
I had been taught not to use goto or switch. However a lot of professional code uses both.
Is the switch statement any faster than a lot of if anf else if's? In other words, is switch the same thing as a lot of if else ifs from a machine code point of view?
|
|
|
|
|
I agree it's a good idea to avoid goto, but in my opinion there are correct applications for switches and I would not be surprised to see them in professional code.
I doubt there is much difference between if's and switches in terms of speed. I think the main issue is clarity. The switch is just easier to read if there are a lot of states to be tested.
Best Regards
Cliff
-- modified at 5:11 Sunday 4th September, 2005
|
|
|
|
|
With today's compilers, switches and ifs can perform about the same. You will often find that a compiler will convert a switch statement to a series of ifs and maybe even visa-versa.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
While there may be a valid use for goto , I've not used it in years. You can always organize your code so that it isn't necessary, and the modified code is almost invariably more robust.
I am curious. Why were you taught to not use switch ? While it can be misused, overall it has its applications. Any time you have a discrete value (an enum , for example) that specifies an action, a switch statement is appropriate.
The object-oriented programming crowd would argue that you should create a class structure, and derive unique classes for each case. That approach is inefficient and overkill a lot of the time. It also makes it a lot more difficult to follow program logic.
Software Zen: delete this;
|
|
|
|
|
I agree. Thanks for your response.
|
|
|
|
|
////////////////////////////func A: App's member function ////////////////////////////////////////////////////
newIndex = pRWapp->GetEmptySocket();
if ( newIndex != -1 )
{
myOver = &(pRWapp->m_clientStructArray[newIndex]);
SOCKADDR_IN clntAddr;
int addrLen = sizeof(clntAddr);
myOver->socket = accept( pRWapp->m_serverSocket, (SOCKADDR*)&clntAddr, &addrLen );
if(pRWapp->m_bKillThreads==TRUE)
{
return 0L;
}
if(myOver->socket == INVALID_SOCKET)
{
// this area left out...for shortness
}
memcpy(&(myOver->clntAddr),&clntAddr,addrLen);
if ( myOver->socket != INVALID_SOCKET )
{
user = newIndex * 2;
ZeroMemory( &(myOver->recvOverlapped.Overlapped), sizeof(OVERLAPPED) );
ZeroMemory( &(myOver->sendOverlapped.Overlapped), sizeof(OVERLAPPED) );
CreateIoCompletionPort( (HANDLE)(myOver->socket),
pRWapp->m_gCompletionPort, DWORD(myOver), 0 );
myOver->recvOverlapped.wsabuf.buf = myOver->recvOverlapped.buffer;
myOver->recvOverlapped.wsabuf.len = BUFSIZE - 1;
==> this Func A 's function is to save data to m_clientStructArray[]....
////////////////////////////func B : App's member function ////////////////////////////////////////////////////
CPortClientScks* pPortCliSkc = new CPortClientScks;
pPortCliSkc->sockHandle = m_clientStructArray[index];
m_XXX_Port_SockList.AddTail(pPortCliSkc);
==> func B 's function is to save m_clientStructArray 's content to m_XXX_Port_SockList....
////////////////////////////func C: App's function////////////////////////////////////////////////////
POSITION sndXXXPos ;
sndXXXPos = m_XXX_Port_SockList.GetHeadPosition();
CPortClientScks* pSndXXXSck = NULL;
while(sndXXXPos != NULL )
{
pSndXXXSck = (CPortClientScks*)m_XXX_Port_SockList.GetNext(sndXXXPos);
if(m_pSndXXXSck->sockHandle.ID != "")
{
DWORD sendbytes;
strncpy(pSndXXXSck->sockHandle.sendOverlapped.wsabuf.buf,(LPCTSTR) pByte, bytes);
pSndXXXSck->sockHandle.sendOverlapped.wsabuf.len = bytes;
WSASend( pSndXXXSck->sockHandle.socket, &(pSndXXXSck->sockHandle.sendOverlapped.wsabuf),1,
&sendbytes, 0, &(pSndXXXSck->sockHandle.sendOverlapped.Overlapped), NULL );
}
}
//////////////////////////// following three lines are added to last of func C to check out the content of m_XXX_Port_SockList /////////////////////
sndXXXPos = m_XXX_Port_SockList.GetHeadPosition();
if(sndXXXPos != NULL)
pSndXXXSck = (CPortClientScks*)m_XXX_Port_SockList.GetNext(sndXXXPos);
==> func C' function is to look over m_XXX_Port_SockList's content...
and the structure of SOCKHANDLE IS....
typedef struct _MYSOCKHANDLE
{
SOCKET socket;
char ID[MAX_ID_LEN];
SOCKADDR_IN clntAddr;
MYOVERLAPPED recvOverlapped;
MYOVERLAPPED sendOverlapped;
}SOCKHANDLE, *LPSOCKHANDLE;
this SOCKHANDLE structure is used at m_clientstructArray[], and m_xxx_port_sockList's node member
the problem of this my code is that Getnext returns different value at second GetNext at added 3 lines especially after comed out of func C 's while loop....
but pPortCliSkc's value returned from func B 's new has proper value....
but, func C 's added GetNext return another value.....
why this happens?
GetHeadPosition 's return value is always same but
GetNext value is different , inside of Fucn C's while loop first entered,
but come out of while loop and added Getnext's return value is different ?
why?
please help me....
-- modified at 21:36 Saturday 3rd September, 2005
|
|
|
|
|
I get a fatal error from an article posted on here.
http://www.codeproject.com/w2k/makexp.asp
Here's the exact error:
http://students.etsu.edu/zbkc9/error.png[^]
I've also tried include fstream without the .h and get different errors. Any ideas? Thanks. I'm wanting to learn C++ and I have Visual Studio .NET 2003 Professional. NOt sure if the version matters, but thought I would post it in case.
|
|
|
|
|
Try
<br />
#include <fstream><br />
using namespace std;<br />
It should work without the using statment, but then you'll need to preface with std::...
std::ofstream out("blah.txt");
He is smart. He will make our Windows go.
-- modified at 21:20 Saturday 3rd September, 2005
|
|
|
|
|
<fstream.h> is not part of the C++ standard, and should not be used in any new code.
It's not portable to modern compilers like VC++ 7.x
Should use <fstream> which is part of the C++ standard, and then use using namespace std, or prefix your types with std::
Top ten member of C++ Expert Exchange.
http://www.experts-exchange.com/Cplusplus
|
|
|
|
|
Hi all!
I'm searching a way to use the sql limit statement in my recordset (derived from CRecordset). Someone knows a way to do so?
In deep love
maTzeLein
|
|
|
|
|
Hi All
After running the program when I saw memory usage of this program in "Task Manager" then noticed that memory usage by program is continually increasing,
Though I am not doing any activity on the program.
Why is this taking place ?
Please reply
Thanks
|
|
|
|
|
Hello,
You probably got a memory leak somewhere in a function that gets called frequently!
You can use Visual Leak Detector[^] tp track any of these leaks down in a debug build. Run the program in the debugger and on exit, it will report all leaks in your program.
Is your program multithreaded by the way?
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Hi
I am hooking into createfile API to differentiate between File open and File create . I am not ablt to differnetiate between the two operations.
In win2000 , CREATE_NEW is not at called and it is always giving OPEN_EXISTING .Further if i create a notepad file i am getting CREATE_ALWAYS . But if i create a .xls file i am getting OPEN_EXISTING
In win2003 , I am able to differentiate between Creation and open.
|
|
|
|
|
I don't know if here is the right place for this question.
I'm creating a setup project in Visual Studio .Net and i want to register a file type (say .jk) with a custom icon. In VS enviroment the only way to do this (i think) is to associate the file type with an executable. But this is not my case. I want the file .jk just to have my icon and nothing more. As you know there are files in Windows that display custom icons but are not associated with executables, so when you double click them you get a shell "Open With" dialog.
Any ideas how to deal with this?
|
|
|
|
|
I do not know how as I have never done that. But I would think it would be a registry entry that holds the data for that. So what I would do is find a file exetension that does what you want, then do a registry search for that extension. You should then be able to figure out what is entered in the registry and copy that for your own extension.
It might take a bit of detective work and some trial and error.
Good luck
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
|
Try starting here[^] in the MSDN.
Software Zen: delete this;
|
|
|
|
|
Hi,
I have a problem working with Html Help Workshop.
I paste pictures from Rational into Word and after I save the document as .htm and use it in Html Help Workshop the picture is not shown.
I don't know if this a bug.
Can you help me please?
|
|
|
|
|
Try looking at the HTML. There should be an <img src="file"> tag where the picture would be. Make sure the file exists, and contains the picture. You will need to add file to your help project as well.
Software Zen: delete this;
|
|
|
|
|
Hey guys, I`ve got a problem with Borland C++ Builder.
I have a code that I need but it`s written on BCB. And I need to do this code on VC++.
Almost all that code is easy, but I can`t find in VC++ function like
Graphics::TBitmap in BCB
Does anyone knows how can I change that function to work in VC?
Will be glad to any answer.
|
|
|
|
|
|
In the program this is for working with video stream in avi files...
Here is full class:
class PASCALIMPLEMENTATION TBitmap : public TGraphic
{
typedef TGraphic inherited;
private:
TBitmapImage* FImage;
TCanvas* FCanvas;
bool FIgnorePalette;
bool FMaskBitsValid;
bool FMaskValid;
TColor FTransparentColor;
TTransparentMode FTransparentMode;
void __fastcall Changing(System::TObject* Sender);
void __fastcall CopyImage(HBITMAP AHandle, HPALETTE APalette, const tagDIBSECTION &DIB);
void __fastcall DIBNeeded(void);
void __fastcall FreeContext(void);
TCanvas* __fastcall GetCanvas(void);
virtual HBITMAP __fastcall GetHandle(void);
TBitmapHandleType __fastcall GetHandleType(void);
virtual HBITMAP __fastcall GetMaskHandle(void);
bool __fastcall GetMonochrome(void);
TPixelFormat __fastcall GetPixelFormat(void);
void * __fastcall GetScanline(int Row);
TColor __fastcall GetTransparentColor(void);
void __fastcall NewImage(HBITMAP NewHandle, HPALETTE NewPalette, const tagDIBSECTION &NewDIB, bool
OS2Format, Classes::TStream* RLEStream);
void __fastcall ReadStream(Classes::TStream* Stream, int Size);
void __fastcall ReadDIB(Classes::TStream* Stream, unsigned ImageSize);
void __fastcall SetHandle(HBITMAP Value);
virtual void __fastcall SetHandleType(TBitmapHandleType Value);
void __fastcall SetMaskHandle(HBITMAP Value);
void __fastcall SetMonochrome(bool Value);
void __fastcall SetPixelFormat(TPixelFormat Value);
void __fastcall SetTransparentColor(TColor Value);
void __fastcall SetTransparentMode(TTransparentMode Value);
bool __fastcall TransparentColorStored(void);
void __fastcall WriteStream(Classes::TStream* Stream, bool WriteSize);
protected:
virtual void __fastcall Changed(System::TObject* Sender);
virtual void __fastcall Draw(TCanvas* ACanvas, const Windows::TRect &Rect);
virtual bool __fastcall GetEmpty(void);
virtual int __fastcall GetHeight(void);
virtual HPALETTE __fastcall GetPalette(void);
virtual int __fastcall GetWidth(void);
void __fastcall HandleNeeded(void);
void __fastcall MaskHandleNeeded(void);
void __fastcall PaletteNeeded(void);
virtual void __fastcall ReadData(Classes::TStream* Stream);
virtual void __fastcall SetHeight(int Value);
virtual void __fastcall SetPalette(HPALETTE Value);
virtual void __fastcall SetWidth(int Value);
virtual void __fastcall WriteData(Classes::TStream* Stream);
public:
__fastcall virtual TBitmap(void);
__fastcall virtual ~TBitmap(void);
virtual void __fastcall Assign(Classes::TPersistent* Source);
void __fastcall Dormant(void);
void __fastcall FreeImage(void);
virtual void __fastcall LoadFromClipboardFormat(Word AFormat, unsigned AData, HPALETTE APalette);
virtual void __fastcall LoadFromStream(Classes::TStream* Stream);
void __fastcall LoadFromResourceName(unsigned Instance, const AnsiString ResName);
void __fastcall LoadFromResourceID(unsigned Instance, int ResID);
void __fastcall Mask(TColor TransparentColor);
HBITMAP __fastcall ReleaseHandle(void);
HBITMAP __fastcall ReleaseMaskHandle(void);
HPALETTE __fastcall ReleasePalette(void);
virtual void __fastcall SaveToClipboardFormat(Word &Format, unsigned &Data, HPALETTE &APalette);
virtual void __fastcall SaveToStream(Classes::TStream* Stream);
__property TCanvas* Canvas = {read=GetCanvas};
__property HBITMAP Handle = {read=GetHandle, write=SetHandle, nodefault};
__property TBitmapHandleType HandleType = {read=GetHandleType, write=SetHandleType, nodefault};
__property bool IgnorePalette = {read=FIgnorePalette, write=FIgnorePalette, nodefault};
__property HBITMAP MaskHandle = {read=GetMaskHandle, write=SetMaskHandle, nodefault};
__property bool Monochrome = {read=GetMonochrome, write=SetMonochrome, nodefault};
__property TPixelFormat PixelFormat = {read=GetPixelFormat, write=SetPixelFormat, nodefault};
__property void * ScanLine[int Row] = {read=GetScanline};
__property TColor TransparentColor = {read=GetTransparentColor, write=SetTransparentColor, stored=TransparentColorStored
, nodefault};
__property TTransparentMode TransparentMode = {read=FTransparentMode, write=SetTransparentMode, default=0
};
};
In the program used next:
Graphics::TBitmap* FThumb;
and
FThumb->Width = lpbih->biWidth;
FThumb->Height = lpbih->biHeight;
But where is in that class Width and Height I don`t know...
|
|
|
|