Are there known issues with sscanf()?

Discussion about other targets
Post Reply
DJ Sures
Member
Posts: 67
Joined: Sun Dec 11, 2022 12:41 pm

Are there known issues with sscanf()?

Post by DJ Sures »

I cannot get %c to work with sscanf(). See this code...

Code: Select all

uint8_t _srcUA = 0;
uint8_t _srcDrive =  'a';
uint8_t _srcName[15] = { 0 };

uint8_t * src2 = "a:2:asdfsf";
  
sscanf(src2, "%c:%u:%s", &_srcDrive, &_srcUA, _srcName);

printf("%u - %u - %s - %s \n", _srcDrive, _srcUA, _srcName, src2);
Which returns...
Capture.PNG
You do not have the required permissions to view the files attached to this post.
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: Are there known issues with sscanf()?

Post by dom »

No, there's a problem with your code :)

Code: Select all

uint8_t _srcUA = 0;
  
sscanf(src2, "%c:%u:%s", &_srcDrive, &_srcUA, _srcName);
_srcUA needs to be uint16_t (since you're using %u) otherwise you end up overwriting values on the stack which in the case happens to be _srcDrive...
DJ Sures
Member
Posts: 67
Joined: Sun Dec 11, 2022 12:41 pm

Re: Are there known issues with sscanf()?

Post by DJ Sures »

Oh my yes - geez that’s what I get for late night coding. Why did I not see that haha. Apologies for my sloppiness lol
Post Reply