|
I am trying to get a int varibale into a char variable. any help here?
int temp = 20;
char *demo = (char) temp;
|
|
|
|
|
int temp =20;
char demo =(char) temp; // failed if temp > 128
|
|
|
|
|
Failed if temp >128?
what does it mean the addressing or the value?
|
|
|
|
|
elvis8900 wrote:
what does it mean the addressing or the value?
I believe it's the value.
(signed) char holds number from -127 to 128, due to its nature of 8-bit capacity (2^8).
|
|
|
|
|
-128 to 127.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
As a signed char is a 1 byte value (Range: -128 to 127), it can be used to hold values only within the range. The most significant bit (MSB) of the char variable is used to denote a negative or a positive value stored in it. If the MSB is ON (1), it means a negative value stored in the 7 bits remaining.
An unsigned char , on the other hand, can hold values ranging from 0 to 255.
An int is a 2 byte value (N.B.: In a 32-bit platform, it is a 4-byte value). Whichever way, if you're trying to store an int in a char variable, it will ONLY store the first byte (because char can only have a byte).
That means, if:
int n = 50;
char c = (char) n;
But, if:
int n = 300;
char c = (char) n; I hope this explains in detail.
Nirav
* Don't wish it was easier, wish you were better! *
|
|
|
|
|
Hello everyone.....
Could someone help me to find a suitable book for memory handling in MS Visual C++? I'm also interested about I/O handling.
Thx,
(w)
|
|
|
|
|
wallyka wrote:
find a suitable book for memory handling
Do you have a specific project in mind? Will you need to handle a lot of memory (> 1 GB)?
John
|
|
|
|
|
An excellent book I would recommend to have, is:
* Programming Applications for Microsoft Windows
- By Jeffrey Richter
- Microsoft Press.
* Don't wish it was easier, wish you were better! *
|
|
|
|
|
Hi,
Is it possible like on Unix to have a program dump a file with a stack trace for ease of debugging? If so, how? Thanks.
|
|
|
|
|
Yeah visual studio also has something like it. When you are debuging a application and you come with an exception, you click on retry and select debug/view/stack
"When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)
|
|
|
|
|
Is there a Visual .NET 2003 equivalent of the .bsc file found in Visual C++ ver 6?
I am the handsome one in the crowd.
|
|
|
|
|
I'm a VB developer and i'm making a software that use a multiport video capture card.
I need to use directshow in order to select the video composite-in. I know i need to use the crossbar filter but i'm a novice in c++ programing.
Please help me to resolve my problem.
Thanks
|
|
|
|
|
Who can explain :
char *m="az";
cout << m << endl;
i=0;
cout << m[i++] << m[i++] << endl ;
i=0;
((cout.operator<<(m[i++])).operator <<( m[i++])).operator <<(endl) ;
Gives (Visual C++) 6.0 :
az
za
za
Thanks .
|
|
|
|
|
Using more than one ++ or -- operator on anything but a line by themselves is always risky. Looking at the statement:
cout << m[i++] << m[i++] << endl; the i++ statement gets executed first, and that value (1) is used with the [] operator.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
sorry but the value of i used by the [] operator will be 0 ...
I think you're confused whith ++i ...
|
|
|
|
|
cout << i++ << i++ << endl; Stepping into the code for ostream& ostream::operator<<(int n) revealed that n had a value of 1 the first time, and a value of 0 the second time. Had the pre-increment operator been used instead, a subscript-out-of-range error would have been realized since the value of n would have been 2 the first time through. Separating the i++ operations into two statements solves all the problems.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Um, no.
The problem here is the undefined behavior of the multiple ++ operations which does get you into some problems.
int i = 0;
cout << m[i++] << endl;
This code would fetch the 0'th value. The ++ and -- operators are not risky when you know how to use them. They have well defined behaviors and undefined behaviors.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
In the second and third cout statements, you are modifying the value of i more than 1 time between sequence points. The result of this is undefined behavior - the compiler can output anything it wants.
|
|
|
|
|
// Loading bitmap image from file
bool ResLoad = SrcImage.LoadBMP24Image(szFileName);
Does anyone knows how this statement actualy loads the file?<br />
Below is the function for it i think
bool CBMPImage::LoadBMP24Image(const char* szFileName)
{
FILE* bmp = fopen (szFileName,"rb");
if (!bmp) return false;
BITMAPFILEHEADER BMPFileHeader;
BITMAPINFOHEADER BMPHeader;
fread (&BMPFileHeader,sizeof(BITMAPFILEHEADER),1,bmp);
fread (&BMPHeader,sizeof(BITMAPINFOHEADER),1,bmp);
if (BMPFileHeader.bfType != 0x4d42) {fclose (bmp); return false;}
if (BMPHeader.biSize != sizeof(BITMAPINFOHEADER)) {fclose (bmp); return false;}
if (BMPHeader.biPlanes != 1) {fclose (bmp); return false;}
if (BMPHeader.biCompression != BI_RGB) {fclose (bmp); return false;}
unsigned long BitColor = BMPHeader.biBitCount;
|
|
|
|
|
Goh,
Hope this helps...
FILE* bmp = fopen (szFileName,"rb"); // creates a FILE pointer szFileName
is char[] containing the file name that is passed to the operation.
if (!bmp) return false;//if null e.g no file found
BITMAPFILEHEADER BMPFileHeader;//create handles for the file
BITMAPINFOHEADER BMPHeader;
//fread does the actual loading
fread (&BMPFileHeader,sizeof(BITMAPFILEHEADER),1,bmp);
fread (&BMPHeader,sizeof(BITMAPINFOHEADER),1,bmp);
//check for valid headers date etc..
if (BMPFileHeader.bfType != 0x4d42) {fclose (bmp); return false;}
if (BMPHeader.biSize != sizeof(BITMAPINFOHEADER)) {fclose (bmp); return false;}
if (BMPHeader.biPlanes != 1) {fclose (bmp); return false;}
if (BMPHeader.biCompression != BI_RGB) {fclose (bmp); return false;}
unsigned long BitColor = BMPHeader.biBitCount;
so if success bmp contains a pointer to the bitmap file.
Does this help???? or do you need more info, not sure of your experience etc..
Ross W
|
|
|
|
|
I am a beginner trying to understand the codes
so where does the function knoe which file to create a file pointer. Where should the filename be placed
Thank alot
|
|
|
|
|
The key is szFilename, this will be a character array (string)
that will contain the path of the physical file, like "c:\SomeBitmap.bmp" look for the definition of szFilename
before the call below:
bool ResLoad = SrcImage.LoadBMP24Image(szFileName);
It may well of come from a dialog in which case it would have come from a member variable...
The key thing is that you could simply do this:
bool ResLoad = SrcImage.LoadBMP24Image("c:\\SomeBitmap.bmp");
If there is anything else please ask
|
|
|
|
|
Dear rw104,
Can I have your ICQ or msn number as i feel it is slow to ask you in this way.
I still got lots of queries. Can I sent you the file to take a look thx
Hui Beng
Thx
|
|
|
|
|
Hello,
I'm trying the following code in an MFC project, which is causing a compiler error. I hope you can guide me with any error/mistake in my code:
My Code:
...
#include <MyClass.h>
#include <vector>
...
vector<CString> *g_pvecStrings;
...
void g_MyOtherFunction(void);
...
void CMyClass::MyFunction(void)
{
vector<CString> vecStrings;
...
g_pvecStrings = vecStrings;
...
g_MyOtherFunction();
...
vecStrings.clear();
}
void g_MyOtherFunction(void)
{
CString csMyStr;
...
g_pvecStrings->push_back(csMyStr);
...
}
The MSVC++ 6.0 (SP5) compiler error for the statement marked as (1) above:
error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::vector<class CString,class std::allocator<class CString> >' (or there is no acceptable conversion)
Please reply on this...
Thanks,
Rgds,
Nirav Doshi
* Don't wish it was easier, wish you were better! *
|
|
|
|