Go Down

Topic: sscanf broken for 64 bit numbers? Eh? (Read 89 times) previous topic - next topic



How do I sccanf uint64_t data?

Code: [Select]

void setup() {

void loop()
  auto buffer = "1337";
  uint64_t try_get_back_number;
  sscanf(buffer, "%llu", &try_get_back_number);
  Serial.println((int)try_get_back_number);//prints 514

Compared the C++

Code: [Select]
#include <iostream>

int main()
const auto buffer = "1337";
uint64_t try_get_back_number;
std::sscanf(buffer, "%llu", &try_get_back_number);
std::cout << static_cast<int>(try_get_back_number) << std::endl;
//prints 1337


Code: [Select]
  Serial.println((int)try_get_back_number);//prints 514
What on earth possessed you to cast the uint64_t to an int?
The art of getting good answers lies in asking good questions.


Oct 18, 2017, 04:53 pm Last Edit: Oct 18, 2017, 04:56 pm by johnwasser
I don't think AVR-LibC supports '%llu'

You can print out the return value from sscanf() to get an idea of what went wrong.  It should return 1 if your one format string was matched successfully.  I suspect it will return 0 or -1 (EOF).
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

Go Up