cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert char to int ?

poompopy
Associate
Posted on August 19, 2015 at 05:06

I want to recieve data From Visual Studio. (UART)

Visual Studio send data 'SDC 50.0'    // SDC 50.0 is char

I want  50.0 only but I don't need SDC

Iwant 50.0  to take it something About interger

Please Help me 

3 REPLIES 3
Posted on August 19, 2015 at 05:57

So can't you just parse one character at a time multiplying by 10?

integer or float?

Thought about atoi(), atof() or sscanf() ??

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
uc2013135191
Associate II
Posted on August 19, 2015 at 06:06

Hi,

This is more of a basic programming question.

Have you tired to google? It's something you really should learn to do more and learn to filtrate all the info available.

First result from a search with ''char to int'':

http://stackoverflow.com/questions/5029840/convert-char-to-int-in-c-and-c

If it's possible to not have it beginning with letters you can use the function ''atoi''.

or if it's always 3 leters before you can just do ''str+3'' and you will have a string starting on that 5. The problem I see right there is, you do know that is not a int right? It has a decimal number (even though it's 0 here).

''atof'' function should work on doubles and floats but note that is not exactly efficient, and you will still need to give that function a string starting with the numbers.

Maybe you making your how methods would be better. Just check if the char is a letter or a number, when you reach the number just start converting to int until you get to the ''.'', then the rest is decimal numbers. C'mon that was like the most common exercise in my first semester of programming and will surely be better for a microcontroller if employed correctly. You should avoid using things like sprintf, functions that are used a lot when manipulating strings in a computer in programming classes.

poompopy
Associate
Posted on August 19, 2015 at 09:15

Sorry, It's float