How to convert char to int?
#1 OFFLINE
Posted 19 June 2012 - 12:09 PM
DATETIME dt;
REQUEST_DATEANDTIME_GET(SYNC,&dt);
I want convert the dt.date to int
#2 OFFLINE
Posted 20 June 2012 - 09:15 AM
//char * to int
int atoi( char* pStr )
{
int iRetVal = 0;
int iTens = 1;
if ( pStr )
{
char* pCur = pStr;
while (*pCur)
pCur++;
pCur--;
while ( pCur >= pStr && *pCur <= '9' && *pCur >= '0' )
{
iRetVal += ((*pCur - '0') * iTens);
pCur--;
iTens *= 10;
}
}
return iRetVal;
}
Edited by adrian_diesel, 20 June 2012 - 09:16 AM.
#3 OFFLINE
Posted 20 June 2012 - 11:53 AM
adrian_diesel, on 20 June 2012 - 09:15 AM, said:
//char * to int
int atoi( char* pStr )
{
int iRetVal = 0;
int iTens = 1;
if ( pStr )
{
char* pCur = pStr;
while (*pCur)
pCur++;
pCur--;
while ( pCur >= pStr && *pCur <= '9' && *pCur >= '0' )
{
iRetVal += ((*pCur - '0') * iTens);
pCur--;
iTens *= 10;
}
}
return iRetVal;
}
AND THE CHAR HOW TO CONVERT STRID
#4 OFFLINE
Posted 21 June 2012 - 01:14 PM
{
int f;
char buf[4];
wchar_t wstring[4];
snwprintf(wstring,4,L"%d",time);
wstr2strn(buf, wstring,20);
f = _fopen(L"/tpa/preset/system/settings",filename, 0x204,0x180, 0);
fwrite(f,buf,20);
fclose(f);
}
STRID gettime(wchar_t *filename)
{
int f;
STRID timed;
f = _fopen(L"/tpa/preset/system/settings",filename, 0x108,0x180, 0);
FSTAT fs;
fstat(L"/tpa/preset/system/settings",filename,&fs);
char buf[8];
wchar_t wstr[16];
memset(buf, 0, 8);
buf[fread( f, buf,fs.fsize)]=0;
fclose(f);
str2wstr(wstr, buf);
timed=Str2ID(wstr,0,SID_ANY_LEN);
return timed;
}
int main (void)
{
DATETIME dt;
REQUEST_DATEANDTIME_GET(SYNC,&dt);
settime(dt.time.sec, L"s.bin");
wchar_t ws[8];
snwprintf(ws,8,L"%d",(dt.time.sec//this char - gettime(L"s.bin")//this STRID));//How to convert this STRID to CHAR and then get them the difference's value and then MessageBox??
MessageBox( EMPTY_SID,Str2ID(ws,0,SID_ANY_LEN),0xffff,1,0,0);
Edited by hel2o, 21 June 2012 - 01:16 PM.
#5 OFFLINE
Posted 21 June 2012 - 01:47 PM
Personal messages that have no need to be private will not be answered. We have a forum for asking questions so please use it.
#6 OFFLINE
Posted 23 June 2012 - 02:37 PM
But I don`t know how to get the difference between the two so you might have to convert to int using adrian_diesels method.
Out of curiosity, what is it that you are trying to do overall?
#7 OFFLINE
Posted 25 June 2012 - 02:03 PM
1mike, on 23 June 2012 - 02:37 PM, said:
But I don`t know how to get the difference between the two so you might have to convert to int using adrian_diesels method.
Out of curiosity, what is it that you are trying to do overall?
Get phone running time
#8 OFFLINE
Posted 25 June 2012 - 06:08 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users



