Use %ls format specifier for README example #469

Closed
endolith wants to merge 1 commit from patch-1 into master
endolith commented 2022-10-20 14:28:26 -05:00 (Migrated from github.com)

I finally got it running, but it was printing only the first character. %ls is for wide strings and works.

https://devblogs.microsoft.com/oldnewthing/20190830-00/?p=102823

"If you want your code to work both on runtimes that use the Windows classic printf rules as well as those that use C standard printf rules, you can limit yourself to %hs for narrow strings and %ls for wide strings, and you’ll get consistent results regardless of whether the format string was passed to sprintf or wsprintf."

I finally got it running, but it was printing only the first character. %ls is for wide strings and works. https://devblogs.microsoft.com/oldnewthing/20190830-00/?p=102823 "If you want your code to work both on runtimes that use the Windows classic printf rules as well as those that use C standard printf rules, you can limit yourself to %hs for narrow strings and %ls for wide strings, and you’ll get consistent results regardless of whether the format string was passed to sprintf or wsprintf."
Youw (Migrated from github.com) approved these changes 2022-10-20 14:55:49 -05:00
Youw (Migrated from github.com) left a comment

Thanks!

Thanks!
endolith commented 2022-10-20 16:38:10 -05:00 (Migrated from github.com)

(It probably should exit when hid_open returns NULL, also, or it produces SIGSEGV when the device isn't plugged in. Confusing for beginners like me.)

(It probably should exit when hid_open returns NULL, also, or [it produces SIGSEGV when the device isn't plugged in](https://github.com/signal11/hidapi/issues/285#issuecomment-239636071). Confusing for beginners like me.)
endolith commented 2022-10-20 16:55:00 -05:00 (Migrated from github.com)
Also apparently [you can't output with `printf` and `wprintf` in the same file](https://stackoverflow.com/a/8682010/125507)...
Youw commented 2022-10-20 17:13:30 -05:00 (Migrated from github.com)

I guess for beginners the hidtest would be a better sample and it was updated/improved over time a lot.

I you want to improve sample in the README (e.g. replace wprintf with printf as it is used in hidtest) - you're very welcome to do so.

I guess for beginners the [hidtest](https://github.com/libusb/hidapi/blob/master/hidtest/test.c) would be a better sample and it was updated/improved over time a lot. I you want to improve sample in the README (e.g. replace `wprintf` with `printf` as it is used in `hidtest`) - you're very welcome to do so.
endolith commented 2022-10-20 17:55:56 -05:00 (Migrated from github.com)

@Youw Yeah, I'm just new to this and not sure of the conventions, but I'll try.

@Youw Yeah, I'm just new to this and not sure of the conventions, but I'll try.

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-libusb/hidapi!469
No description provided.