Skip to main content
Graduate
January 3, 2025
Solved

Function atoi()

  • January 3, 2025
  • 1 reply
  • 937 views

 

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

    This topic has been closed for replies.
    Best answer by StrangeTau

    Oops, my mistake..!

    # uint8_t datatype range : 0~255

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

    1 reply

    StrangeTauAuthorAnswer
    Graduate
    January 3, 2025

    Oops, my mistake..!

    # uint8_t datatype range : 0~255

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