11 years, 8 months ago.

STRING TO DECIMAL

is there any command that i can convert a ASCII data to a decimal number.

1 Answer

11 years, 8 months ago.

sscanf is probably fits your requirements best, see: http://www.cplusplus.com/reference/cstdio/sscanf/, see also scanf there for a bit more examples.

So you would get something for an integer like:

char numberstring[] = "42";
int number;

sscanf(numberstring, "%d", &number);

Accepted Answer

I have a program like this.

rx[1]='5'; float r;

sscanf(rx[1],"%f",&r);

BUT IT DOES'T WORK BECAUSE THERE IS A PROBLEM THAT TELLS :"char is incompatible with the parameter const"

i need that mi variable r get the rx[1]:

r=5;???

posted by Danilo Teran 05 Apr 2013

Do you only have a single char? So no string? Then you can use:

float r = rx[1] - 48;

Since in ascii numbers start at 48.

But you can also use sscanf, how did you define rx? You need to put just 'rx' in the sscanf function, not rx[1].

posted by Erik - 06 Apr 2013