Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document or fix interaction of scn::prompt and result range() #56

Closed
dancingbug opened this issue Mar 15, 2022 · 3 comments
Closed

Document or fix interaction of scn::prompt and result range() #56

dancingbug opened this issue Mar 15, 2022 · 3 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@dancingbug
Copy link

Hi. Modifying the first example given in the README, I have:

#include <scn/scn.h>
#include <cstdio>

int main() {
    int i, j;
    // Read an integer from stdin
    // with an accompanying message
    auto res = scn::prompt("What's your favorite number? ", "{}", i);
    scn::scan(res.range(), "{}", j);
    printf("Oh, cool, %d!\n", i);
    printf("Oh, even cooler, %d!\n", j);
}
// Example invocation:
// What's your favorite number? 345 6789
// Oh, cool, 345!
// Oh, even cooler, 9!

My "678" got eaten unexpectedly!
Please make scnlib give it back, or if this is expected, document obviously the behavior of using range() to scan leftover input from different possible types.

I am using version 1.1

@eliaskosunen eliaskosunen added the bug Something isn't working label Mar 15, 2022
@eliaskosunen eliaskosunen added this to the 1.1.1 milestone Mar 15, 2022
@eliaskosunen eliaskosunen self-assigned this Mar 15, 2022
@eliaskosunen
Copy link
Owner

The file handling stuff is a little iffy and hard to test when using stdin, but this definitely should have been caught. I'll look into this.

eliaskosunen added a commit that referenced this issue Mar 16, 2022
eliaskosunen added a commit that referenced this issue Mar 16, 2022
@eliaskosunen
Copy link
Owner

Temporary fix in v1.1.1, the snippet in your message now works.

Keeping the issue open for a more substantial fix, including design changes.

@eliaskosunen eliaskosunen modified the milestones: 1.1.1, 2.x Mar 16, 2022
@eliaskosunen
Copy link
Owner

For the record, this has been fixed in 2.0.

#include <scn/scan.h>

int main() {
    auto res1 = scn::prompt<int>("What's your favorite number? ", "{}");
    auto res2 = scn::scan<int>(res1->file(), "{}");
    printf("%d, %d\n", res1->value(), res2->value());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants