View unanswered posts | View active topics It is currently Fri Aug 01, 2014 12:20 pm






Reply to topic  [ 5 posts ] 
Converting String to Short/Int 
Author Message
Novice

Joined: Mon May 31, 2010 8:02 am
Posts: 55
Post Converting String to Short/Int
Hi,

I have an application where I am reading values from a text file on the NXT and I need to convert some of the read numbers from their character representation to numbers (short/int). For example;

sReadVal = "12";

What is the best way to convert this to a short of 12? Are there any string-to-number conversion functions available?

Thanks,
Chris


Thu Feb 03, 2011 7:38 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Converting String to Short/Int
I don't have RobotC in front of me but I vaguely recall it may support sscanf. If not, check if it supports atoi. If not, you can always write your own :)


Thu Feb 03, 2011 9:24 pm
Profile
Novice

Joined: Mon May 31, 2010 8:02 am
Posts: 55
Post Re: Converting String to Short/Int
Hi,

I don't think RobotC has any of the conversion functions built-in. Certainly not atoi or sscanf. I've written my own for now, but if there are any built-in functions to make it easier, I'd like to know.

Thanks,
Chris


Thu Feb 03, 2011 9:34 pm
Profile
Rookie

Joined: Tue Jul 03, 2012 5:16 am
Posts: 43
Post Re: Converting String to Short/Int
There are. I've used atoi in my programs before. I believe sscanf works as well but I'm not sure how to use it.


Wed Jul 11, 2012 8:36 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 560
Post Re: Converting String to Short/Int
brianchen11 wrote:
There are. I've used atoi in my programs before. I believe sscanf works as well but I'm not sure how to use it.


^^This is correct. Setting a numeric variable (int, long, etc) using atoi and a string will convert the "12" to a numeric 12.

http://www.robotc.net/wiki/Math#atoi

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Wed Jul 11, 2012 9:28 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.