I've got a little problem. Through hyperterminal the user must be able to type in a number which then is used as setpoint for a PID algorithm.
The number can be anything between 1-1000
My code right now looks like this:
char string[10];
long frequency;
... lots of irrelevant code ...
gets(string);
Now! Let's assume the user typed 978. How do I convert the character array to a long? Should I maybe use an all different approach?
Thank you for your help!
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Mon Oct 27, 2008 5:35 pm
Consider that for common problems like this, the C language will
already have a solution -- it's the series of functions known as
"atoi" (ASCII to Integer). In this case, you want a 16-bit result,
so use the version of it called "atol" (ASCII to long). It's in the
CCS manual.
davidbue
Joined: 05 Nov 2007 Posts: 28 Location: Denmark
Posted: Tue Oct 28, 2008 1:09 am
Hi PCM programmer!
I'm so sorry. I forgot to say... I'd like to not use the atoil() as the stdlib.h eats up waaay to much memory when included. :-D
I'm looking for an alternative way to capture the number.
Sorry for the missing information, and thank you so much for your answer.
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