Go Down

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

kandel3

Yo,

How do I sccanf uint64_t data?

Code: [Select]

void setup() {
  Serial.begin(9600);
}

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
}

PaulS

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.

johnwasser

#2
Oct 18, 2017, 04:53 pm Last Edit: Oct 18, 2017, 04:56 pm by johnwasser
I don't think AVR-LibC supports '%llu'
http://www.atmel.com/webdoc/avrlibcreferencemanual/group__avr__stdio_1ga67bae1ad3af79809fd770be392f90e21.html

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