cancel
Showing results for 
Search instead for 
Did you mean: 

Function atoi()

StrangeTau
Associate III

 

Hello,

 

My question is about language Embedded C.

char data[100] = "300 0";

uint8_t* data_a = strtok(data, " "); // data_a printf result : "300"

// printf results data_a[0] : '3', data_a[1] : '0', data_a[2] : '0'

uint8_t* data_b = strtok(NULL, " "); // data_b printf result : "0"

 

uint8_t data_c = atoi(data_a); // data_c print result : 44 // Why??????????

uint8_t data_d = atoi(data_b); // data_d printf result : 0

When the input is the string "300", why  is the output of the function "atoi" integer 44?

 

Any help is greatly appreciated!

 

Friendly regards, Tau

1 ACCEPTED SOLUTION

Accepted Solutions
StrangeTau
Associate III

Oops, my mistake..!

# uint8_t datatype range : 0~255

uin8_t data_c = atoi("300"); // data_c printf result : 44 // Logical error : 300 > 255

View solution in original post

1 REPLY 1
StrangeTau
Associate III

Oops, my mistake..!

# uint8_t datatype range : 0~255

uin8_t data_c = atoi("300"); // data_c printf result : 44 // Logical error : 300 > 255