|
hex, dec, oct are just ways to represent the same integer...
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
yes, the diffrent is the string's represent format, i know how to represent a integer to diffrent format string as
<br />
char *_itoa(<br />
int value,<br />
char *string,<br />
int radix <br />
);
but
int atoi( const char *string );
the function has only one param, no format param
must i write a function to do this?
I love Programming
|
|
|
|
|
an integer is an integer !!!!
it is stored as a serie of bits in memory, wether you stored an hexa value, an octal one, or a decimal one...
int i = 0x05;
<hr>
int i = \005;
<hr>
int i = 5;
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Take a look at the sprintf function instead. It will do what you are looking for (and even much more ).
Hexa:
sprintf(Buffer,"%x",Number);
Decimal:
sprintf(Buffer,"%d",Number);
|
|
|
|
|
An integer is an integer and it doesn't matter how you represent it. If you are trying to print it in different representations you may take a look to print flags[^].
Marc Soleda.
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
xiaohe521 wrote:
int atoi( const char *string );
the function has only one param, no format param
must i write a function to do this?
I think you are trying to convert a hexadecimal number (which is a string) to an integer. Am I right?
|
|
|
|
|
Use the strtol() function to convert numeric strings in various bases into integers.
|
|
|
|
|
How do u convert a Number to an Integer..?
V
|
|
|
|
|
ah... there's now azt least one interresting post on that thread...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
If i have a function myfunc(arg1,arg2,arg3), how can i include them, all, in a va_list variable?
if i use va_start(list, arg1), i won't have arg1 in the list and I cannot change the singnature of the function myfunc.
If I do something like:
list = (va_list)&arg1 it works for types like int, unsigned int, even char*, but not float or double. If one of the args is float, it will store in list a 0 instead of the real value.
please help
|
|
|
|
|
You'd have to include a sizeof(arg1) to account for the stack space used by arg1 and include it. Something like this:
char * ArgPtr = (char *)&arg1 - sizeof(arg1);
if( ArgPtr == (char *)&arg2 )
{
ArgPtr = (char *)&arg1 + sizeof(arg1);
}
list = (va_list)ArgPtr;
That oughta take into account whatever way the stack grows.
Bob Ciora
|
|
|
|
|
Indeed something like that works. Thank you
Now something else troubles me regarding float. I make myself a list of the arguments. the list contains a char*, a float and something. I check them, they are ok. But when i'm tring to right them into a file using vfprintf(file,format,list), instead of my float value i always get a 0.00000
This is too much
|
|
|
|
|
You should always use the va_ family of functions to do this.
Anyway, floats are always pushed as doubles in var arg functions. You can check some assembly listings to verify this.
|
|
|
|
|
Thank you for your help.
Indeed when i use va_arg to extract my float the result is corect, so I'll just use a printf
Thanks again
|
|
|
|
|
Hi
I am trying to connect to SQL server data base using NT authentication from my window service code.
_bstr_t bstrConn = _bstr_t("PROVIDER=SQLOLEDB;SERVER=SD1;DATABASE=MEDICAPT;TRUSTED_CONNECTION=YES;");
m_pConnGenGuiDB->ConnectionString = bstrConn;
m_pConnGenGuiDB->CommandTimeout = 600;
m_pConnGenGuiDB->Open("","","", adConnectUnspecified);
I am getting error Description = Login failed for user 'NT AUTHORITY\SYSTEM'
The same code works fine in any MFC application.
Any body have clue abt that
|
|
|
|
|
I define a struct like this:
typedef struct
{
float blc;
float sx;
float sy;
}ScreenStruct;
Then in the .h,I define a struct pointer :
ScreenStruct *m_Screen;
At last ,I use it in the .cpp as follows:
m_Screen[0].sx=0;
When I run ,it canont be complied.And the result is that
"miss ; (before *)" or "CView::ScreenStruct miss the storage class or class declaration".
How can I do?Thank u.
|
|
|
|
|
why do you declare m_Screen in the .h ? is it global or as it name tell (but you didn't), it is a class member ?
how is it initialized ?
why don't you declare ScreenStruct as a part of your CWiew class ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
yes.I declare the m_Screen in the Cview.h,which include the Cview class,and the m_Screen[0].cx=0 is in the Cview.cpp.
|
|
|
|
|
you didn't answer my question. how do you initialize m_Screen ?
moreover, i asked if you were declaring the struct ScreenStruct directly into the CWiew derived class...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I am sorry.
It initialized in the construction function
Cview::Cview()
{
...
m_Screen[0].sx=m_xStart;
...
} in the Cview.cpp.
The m_xStart is a float variable.
Thank u.
|
|
|
|
|
humm, it seems that you don't really know what you are doing, do you ?
where do you declare the structure ? inside the class, or outside, as a "global" type ?
notice that a talk about the class, not the .h or .cpp file !!!
class Cview {
private:
struct {
float blc;
float sx;
float sy;
} ScreenStruct m_Screen;
public:
Cview();
};
TOXCCT >>> GEII power [toxcct][VisualCalc]
-- modified at 5:18 Wednesday 31st August, 2005
|
|
|
|
|
I think I make a mistake about the naming the class.
and the struct is a gobal type .It is not in the Cview class .So it is not a member of the class Cview.
So it like this:
typedef struct
{
//...
} Struct;
class Cview
{
public: Struct m_Screen;
public: Cview();
//... };
Thank u.
|
|
|
|
|
Ok, so let's start from the begining.
First, you have to declare your structure (that is how it will look like: what are the members). Then when it's done (and only when it's done) you can 'instantiate' a structure like that (that is, you can make use of it as a new instance).
In order to instantiate the structure, the compiler needs to know how it looks like, so it has to be defined before. Put the definition of the structure above the definition Cview class (him, also, this is not a good naming convention, I suggest to name your view class with a name more appropriate, something like CMyView). Then, inside your class, you can declare an instance of this structure:
ScreenStruct m_Screen;
Why do you want to use a pointer ? Do you need more than one (so you need a table of structure) ? If you just need one struct, use this solution instead otherwise you will need to initialize yout table wlike that:
m_Screen = new ScreenStruct[10];
and then delete the memroy afterward (in the destructor of your Cview class for example).
|
|
|
|
|
|
Yes.In my Application ,there are three struct ,so I define the pointer .So I think the pointer is a better way.But as u see, the result is not good.Thank you for your help.
|
|
|
|