|
It says that,network would trans u_long and u_shor values in different order.So when the value would be send and has been recieved,we'd better using such hotnl,htons,ntohs,ntohl fuucntion to convert the data.I relieve it. But another question puzzled me somedays.If the other datas,like string,"kcynic" for example,if each character holds two bytes long(Widechar),the reciever would get a string completely different string.In another words,the origin string is lost.
But it often does not so.Why?
Thanks.
|
|
|
|
|
Good point!
I find this http://en.wikipedia.org/wiki/UTF-16/UCS-2#Byte_order_encoding_schemes[^].
It supports your point of view (string should be scrambled on different encoding machines). I don't know why you, experimentally, found that often the string are not scrambled.
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.
|
|
|
|
|
but i could not open the linker
|
|
|
|
|
How can i make this :
i have this code : csText.Format("%d", nSum);
ok but my result is lets say 44,ok but if i have 22.3+22.3=44.6(nSum)
this is not working : csText.Format("%d", nSum);
How can i make this?(to have the result whit 44.6 lets say not 44)
Bravoone
|
|
|
|
|
nSum is an int value. So it truncates the value up to the decimal point. You need to take a float or a double variable.
// say nSum is float type
csText.Format("%f",nSum);
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
%d is the type format specifier for signed decimal decimal, for floaing point numbers you can use, for instance, %g . see http://msdn2.microsoft.com/en-us/library/hf4y5e3w(VS.80).aspx[^]
(remember that CString::Format behaves like sprintf ).
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.
|
|
|
|
|
CPallini wrote: for floaing point numbers you can use, for instance, %g. see
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Don't you like %g ?
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.
|
|
|
|
|
"%g" is not working !How can i do that ?
Bravoone
|
|
|
|
|
On my system it works pretty well, anyway, see [^] or [^].
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.
|
|
|
|
|
Bravoone_2006 wrote: How can i do that ?
by reading the CString::Format() documentation !
|
|
|
|
|
toxcct wrote: by reading the CString::Format() documentation !
How can I do that?
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
ok,but i need 2 digits 44.66 lets say... then what ?
Bravoone
|
|
|
|
|
Use this format tag: %.2f instead.
|
|
|
|
|
Don't you read documentation, do you?
try:
csText.Format("%.2f", nSum);
BTW nSum is a misnaming for a float if you are using Hungarian Notation.
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.
|
|
|
|
|
csText.Format("%.2f", nSum);
is not working why?
i have read documentation but is not working !any why ?
Bravoone
|
|
|
|
|
Bravoone_2006 wrote: csText.Format("%.2f", nSum);
is not working why?
What do you mean with the generic is not working?
Please detail the misbehaviour (i.e. obtained result vs expected result).
BTW Have you correctly declared nSum as floating point number?
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.
|
|
|
|
|
Maybe he's new to c++.
|
|
|
|
|
try like this:
<br />
float uSum = 12.457 + 345;<br />
CString strFomat;<br />
strFomat.Format(TEXT("%.2f"),uSum);<br />
|
|
|
|
|
How can i do that ? lets say in list i have 44.22+44.22 the result must be in csText 88.44 HOW can i do that?
int nSum = 0;
int uSum = 0;
for( int nRow = 0; nRow < m_list1.GetItemCount();nRow++)
{
if(m_list1.GetCheck(/*index of item*/nRow))
{
csText = m_list1.GetItemText( nRow, 2 );
uSum += atoi( csText);
csText.Format("%.2f",uSum);
m_sum.SetWindowText(csText);
}
}
this code give the result : lets say i have in list 44.22+44.22 the result in csText is 88.00 but i need 88.44 HOW ?
Bravoone
|
|
|
|
|
don't use atoi(). instead use atof()
I think you must read the documentation rather than starting to build on the project. atoi converts a string to int and not to a float and then when you add them it returns an int in uSum which is just printed as a float value.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
ok but... :
uSum += atof( csText);
warning C4244: '+=' : conversion from 'double' to 'int', possible loss of data
Why?
Bravoone
|
|
|
|
|
because nSum has data type int.
|
|
|
|
|
uSum is an int. so you would need to use typecasting or declare uSum as a float.
I think you are missing on the basics.
Bravoone_2006 wrote: ok but... :
uSum += atof( csText);
warning C4244: '+=' : conversion from 'double' to 'int', possible loss of data
It would be better if you read some tutorials on typecasting, using variables and reading some more basics and some more............................and a few more....................
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Bravoone_2006 wrote: Why?
You declare an integer, how would you expect to store a floating point value into it and expect that it still holds a floating point value ? I think you REALLY need to find some good book about the basics of C++. I mean, knowing what an integer and a double are, is at least the bare minimum. It's the thing you learn at very very begining.
|
|
|
|