|
Use %u instead of %d. %d is for signed integers and %u is for unsigned integers.
|
|
|
|
|
The flawn is in %d format specifier. According to documentation [^] %d specifies 'signed decimal integer' hence you unsigned number is first converted to signed and the printed out.
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]
|
|
|
|
|
spicy_kid2000 wrote: if it a unsigned int, it should be 2 ^32 -1
Good. The following snippet may possibly confirm you opinion
void main()
{
unsigned int u = 0;
u = ~u;
printf("%u (%x)\n", u, u);
}
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]
|
|
|
|
|
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char myVar = 0xFF;
printf("Signed: %d\n", myVar);
printf("Unsigned: %d\n", (char unsigned)myVar);
system("Pause");
return 0;
}
Output:
Signed: -1
Unsigned: 255
Press any key to continue . . .
|
|
|
|
|
Hi all.
I want to change a date format from dd/mm/yyyy to yyyy/mm/dd..
suppose i am getting date as..
Date = 12/04/2008 i want it to be changed to 2008/04/12..
I am trying with the below code but i am getting the system time..
the code is
CString Date,Datee;
Date = "12/05/2008;"
SYSTEMTIME sysTime;
GetSystemTime(&sysTime);
Datee.Format("%04d%02d%02d",sysTime.wYear,sysTime.wMonth,sysTime.wDay);
can anyone help me
manju
Hi..
I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++
manju
|
|
|
|
|
manju#123 wrote: I want to change a date format from dd/mm/yyyy to yyyy/mm/dd..
It would help a lot if you would tell us what this date is: is it stored in a plain string, a COLEDataTime object, ... ?
Don't you have the different elements of the data (day, month and year) separately available ?
|
|
|
|
|
manju#123 wrote: SYSTEMTIME sysTime;
GetSystemTime(&sysTime);
Gets the current system time in UTC
manju#123 wrote: I am trying with the below code but i am getting the system time..
because you are using the system time and just formatting it before displaying
manju#123 wrote: Datee.Format("%04d%02d%02d",sysTime.wYear,sysTime.wMonth,sysTime.wDay);
Do you try to print the Datee string after the string is formatted? It should now be in the format you need.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Try using GetLocalTime...
|
|
|
|
|
If you are talking about Date variable then you can get the desired format using -
CString Date = "12/05/2008";
CString YY,MM,DD;
int nLen;
nLen = Date.ReverseFind('/');
YY = Date.Right(nLen - 1);
Date = Date.Left(nLen);
nLen = Date.ReverseFind('/');
MM = Date.Right(nLen);
Date = Date.Left(nLen);
DD = Date;
CString sNewDateFormat;
sNewDateFormat.Format("%s/%s/%s",YY,MM,DD);
And if you are talking about the variable Datee, then the code written by you is fine.
|
|
|
|
|
manju#123 wrote: I am trying with the below code but i am getting the system time..
No surprise there since you are explicitly using sysTime members.
manju#123 wrote: can anyone help me
Yes. To get your yyyy/mm/dd format, use:
Datee.Format("%04d/%02d/%02d", sysTime.wYear, sysTime.wMonth, sysTime.wDay); Now if you are actually wanting to use the date in the Date variable, try:
CString Date = "12/05/2008";
COleDateTime dt;
dt.ParseDateTime(Date);
CString Datee = dt.Format("%Y/%m/%d");
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Hi all,
While adding a variable to a control in the dialog it is not getting reflected in the class.Please kindly help me out
Thank You
|
|
|
|
|
Try deleting the .ncb file and .clw file in your source folder and then reopening it. The intellisense goes wild sometimes.
BTW, how do you add the variable? using the class wizard and which compiler/version do you use?
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Thanks a million.It was indeed intellisense prob.By right clicking the control,variable["Add variable"]was added.Version 6 is being used
|
|
|
|
|
Hi,
I intend to make a sample application in VC++ to using MySQL databases.
Can anybody suggest me where and how to start?
I am new to databases any help would be great.
Thanks in Advance!!
Regards,
Tony
|
|
|
|
|
Visit this page http://www.codeproject.com/KB/database/[^] and set the language filter to C++ and skill to Beginner. There are plenty of articles that may give you a lead to begin with.
Note that there would be nothing specific to MySQL, but they will all speak about databases in general.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
|
Simple 7 Steps
1)First of all import msado15.dll into your workspace
#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
2)Initialize COM libraries using
CoInitialize(NULL);
3) Create connection & record set pointers
_ConnectionPtr pConn("ADODB.Connection");
_RecordsetPtr pRst("ADODB.Recordset");
4) Open data base
#define STR_DATABASE L"DRIVER={sql server};SERVER=serverName;Database=datbaseName;" L"UID=sa; PWD=sa;"
HRESULT hr = S_OK;
hr = pConn->Open(STR_DATABASE, L"", L"", adOpenUnspecified);
if(FAILED(hr))
{
AfxMessageBox ("Error instantiating Connection object\n");
}
5)Execute Query and read values
try
{
CString strSQL("Select * From MyTable");
pRst->Open( _variant_t(strSQL),_variant_t((IDispatch *) pConn, true),adOpenDynamic, adLockReadOnly,adCmdText);
if(!pRst->EndOfFile){
CString strValue = (char*)(_bstr_t)pRst->Fields->Item["FieldName"]- >Value;
int nValue = (long)pRst->Fields->Item["FieldName"]->Value;
}
catch(_com_error &ce)
{
AfxMessageBox(ce.ErrorInfo);
OR
AfxMessageBox(ce.Description());
}
6)Close connection and record set pointers
if(pRst->State == adStateOpen)
pRst->Close();
if(pConn->State == adStateOpen)
pConn->Close();
7)UnInitialized COM library
::CoUninitialize();
|
|
|
|
|
Can i go like this as well
=========================================================================================
try
{
CDaoDatabase* pCDaoDb = NULL;
CDaoRecordset* pPointsSet = NULL;
pCDaoDb = new CDaoDatabase();
pCDaoDb->Open("C:\\temp\\sample2.mdb", FALSE, FALSE, "");
pPointsSet = new CDaoRecordset(pCDaoDb);
if (!pPointsSet->IsOpen())
{
pPointsSet->Open(dbOpenTable, "STUDENT", 0);
}
COleVariant oleVariant;
oleVariant = pPointsSet->GetFieldValue("STUDENTID");
long lTemp = oleVariant.lVal;
oleVariant = pPointsSet->GetFieldValue("Address");
CString strTemp = oleVariant.pcVal;
CString strTemp2 = strTemp.AllocSysString();
int nCount = pPointsSet->GetRecordCount();
//pPointsSet->
}
catch(CDaoException* e)
{
//int nError = e->ReportError();
CString error = e->m_pErrorInfo->m_strDescription;
MessageBox( NULL, error, "ERROR", MB_OK );
}
=========================================================================================
|
|
|
|
|
|
Hi!
I've used the following code to load an Object(A 3D Model).
m_Obj = new Object("Car");
m_Obj->LoadFile("demoMap/StaticMeshes/Pajero.IVE", false);
During Debugging, if I hover over m_Obj and view it as a XML file, it shows me:
"A name contained an invalid character. Error processing resource 'file:///C:/Documents and Settings/RATHAKRISHNAN/Local Set...
<bad ptr="">"
I've to use this variable to apply some material to the 3D Object. There it shows exception. How to overcome this Bad Ptr situation and resolve this exception?
|
|
|
|
|
debug the the LoadFile.
|
|
|
|
|
No. I got an exception while running the project. So I planned to inspect each variable by Debugging. While hover over this m_Obj variable, it shows Bad Ptr.
|
|
|
|
|
What line causes the exception?
m_Obj is an invalid pointer until the "new" succeeds.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I am trying to provide the language support (chinese) to one of my sample application. I have translated the strings with the chinese equivalent strings. It is working fine. When I run the application, I am able to see my sample application GUI with the Chinese strings.
But one thing I would like to know is when I compile my chinese language dll, I am getting the warnings MySampleAppChinese.rc : Could not find the file.
Why are these warnings generated? What is the reason for this?
Thanks in advance.
Taruni
|
|
|
|
|
Hi,
How can initialize array of int with NULL after its declartion.
int a[5]={NULL};//Right?
int a[5];then later how can I do the same above
|
|
|
|