Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Not a best practice, for sure.
What do you mean by this? Can you explain how it uses more memory?
Hey why does this work without including string.h? When I tried using strlen I got a "no implicit function declaration" error...
You are correct; this prompts a warning:
format specifies type 'int' but the argument has type 'size_t'
.Since count is of type size_t, I think the format specifier should be %zu instead of %d.
This comment is hidden because it contains spoiler information about the solution
in the ASCII table you will find '\0' is equal to the demical '0'.
*buffer = 0; is equivalent to *buffer = '\0'
Or, maybe I wrote it this way for fun, not ever intending it to be production code...
This comment is hidden because it contains spoiler information about the solution
Subtracting a size_t from a size_t is not well-defined when the result is negative. You should compare them first to ensure that the result is positive before subtracting them. Also, the use of the ternary operator here is just not necessary.
where did you seen average value as integer? Why that is consider as best practice?
This code can definitely improve. It can invoke undefined behaviour on systems with a signed
char
(on x86_64 for example) ifstring
contains "negative" characters (say the input contains some UTF-8 codepoints). This is becausetolower
is actually supposed take anunsigned char
cast toint
, or alternativelyEOF
, with all other values invoking UB. Plus, you probably don't want to usetolower
anyways as it is locale-dependant. Edit: And also, inconsistent formatting, please move all your pointer asterisks*
to one direction! Remember that the optimal type for sizes, counting, etc in C issize_t
from<stddef.h>
.I love creativity dude. Good job!
This comment is hidden because it contains spoiler information about the solution
Ok its clever solution(i marked you clever) but cant say best practice since a lot of memory is wasted comparing it with normal switch cases. since C is prefered for writting better and faster solution it is not much relible,
shorter code are not always the best...
Loading more items...