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

Rework gigasecond to be slightly more challenging #925

Merged
merged 3 commits into from
Nov 6, 2023

Conversation

glennj
Copy link
Contributor

@glennj glennj commented Nov 4, 2023

I'm not terribly experienced in C. Have I implemented an OK way to handle strings without malloc/free?

Closes #924

@glennj
Copy link
Contributor Author

glennj commented Nov 4, 2023

Hmm I could be wrong but IIRC the intention of the gigasecond exercise is to be relatively simple.
Introducing time.h In any significant way may add needless complexity and could lead to different results depending on platform.

@wolf99 how does this submission meet your concerns?

@@ -1,6 +1,8 @@
#include "test-framework/unity.h"
#include "gigasecond.h"

#define BUFFER_SIZE 20 // "YYYY-mm-dd HH:MM:SS"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#define BUFFER_SIZE 20 // "YYYY-mm-dd HH:MM:SS"
#define BUFFER_SIZE (strlen("YYYY-mm-dd HH:MM:SS") + 1)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively: #define BUFFER_SIZE sizeof("YYYY-mm-dd HH:MM:SS")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively: #define BUFFER_SIZE sizeof("YYYY-mm-dd HH:MM:SS")

That's much better! I don't know why that never occurred to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be a static size_t instead of a #define so it only needs to be calculated once?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be calculated at compile time even if it's a #define.

@ryanplusplus
Copy link
Member

Can you bump up the difficulty for gigasecond in config.json?

@ryanplusplus ryanplusplus merged commit b19ba9f into exercism:main Nov 6, 2023
4 checks passed
@glennj
Copy link
Contributor Author

glennj commented Nov 6, 2023

I was totally Chesterton's Fencing with that construct_date function. Didn't understand why it's there, didn't complain about it ;)

@glennj glennj deleted the rework-gigasecond branch November 6, 2023 00:20
@wolf99
Copy link
Contributor

wolf99 commented Nov 6, 2023

Thanks for this PR @glennj !

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

Successfully merging this pull request may close these issues.

Rework the gigasecond exercise?
4 participants