CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Help parsing a string

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
[email protected]



Joined: 30 Nov 2008
Posts: 5

View user's profile Send private message Send e-mail

Help parsing a string
PostPosted: Fri Apr 03, 2009 8:27 pm     Reply with quote

I have a project that has an SDCARD. I have a FAT file system. I need to open a text file and read in some values.

I have all the file stuff working and I can read in strings, and I can parse the string, the problem is I cannot figure out how to convert the string value to hex.

Here is my sample code.
Code:

while (readln(&fdata,linein,63))
{
strcpy (temp_str, "\0");
strncpy (temp_str, linein + 5 ,  4);
strcpy (temp_str + 4, "\0");
//Copy up to n characters s2->s1
EM_Timer_Settings[Loop_Counter] = atoi(temp_str);

The atoi func works if my number has hex chars. But if no hex chars, it converts the string to decimal.

what is the best way to convert a 4 char string to hex?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 03, 2009 9:12 pm     Reply with quote

atoi() expects to see a "0x" in front of a string, to identify it as hex.

Or, you can make a copy of the source code for atoi() and edit it, so that
it operates only on hex strings. (And give it a new function name).

Or you can write your own function to do it. Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=35175&start=2
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group