Jump to content


How to convert char to int?


  • Please log in to reply
7 replies to this topic

#1 OFFLINE   hel2o

hel2o
  • Members
  • Pip
  • Padawan

  • 41 posts

Posted 19 June 2012 - 12:09 PM

How to convert char to int??



DATETIME dt;
REQUEST_DATEANDTIME_GET(SYNC,&dt);

I want convert the dt.date to int

#2 OFFLINE   adrian_diesel

adrian_diesel
  • New Members
  • n00b

  • 7 posts

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   hel2o

hel2o
  • Members
  • Pip
  • Padawan

  • 41 posts

Posted 20 June 2012 - 11:53 AM

View Postadrian_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   hel2o

hel2o
  • Members
  • Pip
  • Padawan

  • 41 posts

Posted 21 June 2012 - 01:14 PM

void settime(char time,wchar_t* filename)
{
  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   Boysie

Boysie
  • Super Moderators
  • Mrs Miggins

  • 37,211 posts
  • Gender:Can't decide
  • Location:Between a rock and a hard place
  • Mobile:X10 - K800
  • Tutorials Submitted:One or two

Posted 21 June 2012 - 01:47 PM

Topics merged

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   1mike

1mike
  • Members
  • PipPipPip
  • Non-se-nse

  • 146 posts
  • Gender:Male
  • Mobile:K850,K800,W810, K750@W800,W100

Posted 23 June 2012 - 02:37 PM

This might help. It will convert the string to char and display the two values in the message box.
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.
Spoiler

Out of curiosity, what is it that you are trying to do overall?

#7 OFFLINE   hel2o

hel2o
  • Members
  • Pip
  • Padawan

  • 41 posts

Posted 25 June 2012 - 02:03 PM

View Post1mike, on 23 June 2012 - 02:37 PM, said:

This might help. It will convert the string to char and display the two values in the message box.
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.
Spoiler

Out of curiosity, what is it that you are trying to do overall?

Get phone running time

#8 OFFLINE   1mike

1mike
  • Members
  • PipPipPip
  • Non-se-nse

  • 146 posts
  • Gender:Male
  • Mobile:K850,K800,W810, K750@W800,W100

Posted 25 June 2012 - 06:08 PM

Have you tried looking at the source for breakcountdown v1.0 elf by stonos?  At a glance it seems to perform checks against the current time.  Might be helpful but I haven`t looked at it properly yet.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users