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

sscanf does not properly check content after int match. #4

Closed
knubo opened this issue Jul 4, 2024 · 4 comments
Closed

sscanf does not properly check content after int match. #4

knubo opened this issue Jul 4, 2024 · 4 comments

Comments

@knubo
Copy link

knubo commented Jul 4, 2024

sscanf("1 hellp", "%d hello",d);

This one matches and extracts the 1.

@dworkin
Copy link
Owner

dworkin commented Jul 5, 2024

That's how it is in LPmud, so that's how it has to be in DGD to be compatible. Only for %s does the part after the match matter. With %d, %f or %c you have a match up to the end of the number/float/character, and then no match for the part that comes after.

If you do care about the part that comes after, do it like this:
if (sscanf("1 hellp", "%d hello%*s", d) != 2) no_match();

@knubo
Copy link
Author

knubo commented Jul 5, 2024

That's cool. I guess this particular feature of sscanf should be noted in the doc. On Viking Mud our doc, which I believe comes from DGD, states in kfun/sscanf:

"Other characters must be matched exactly."

@dworkin
Copy link
Owner

dworkin commented Jul 5, 2024

Good point. I'll update the documentation.

@dworkin dworkin transferred this issue from dworkin/dgd Jul 5, 2024
@dworkin
Copy link
Owner

dworkin commented Jul 5, 2024

Updated in 55a6bc6.

@dworkin dworkin closed this as completed Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants