|
Page 1 of 1
|
[ 5 posts ] |
|
Converting String to Short/Int
Author |
Message |
SeaLyon
Novice
Joined: Mon May 31, 2010 8:02 am Posts: 55
|
 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 |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 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 |
|
 |
SeaLyon
Novice
Joined: Mon May 31, 2010 8:02 am Posts: 55
|
 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 |
|
 |
brianchen11
Rookie
Joined: Tue Jul 03, 2012 5:16 am Posts: 43
|
 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 |
|
 |
JohnWatson
Site Admin
Joined: Thu May 24, 2012 12:15 pm Posts: 722
|
 Re: Converting String to Short/Int
^^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 updated help documentation and the ROBOTC Forums.
|
Wed Jul 11, 2012 9:28 pm |
|
|
|
Page 1 of 1
|
[ 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
|
|