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.
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>
.tolower() is defined in ctype.h header file, shouldn't you include it?
I agree with this.
But wouldn't it be nicer to get rid of tolower? One can use a switch and "hardcode" both ascii values for x and o respectively. Also we could omit the char *p since we can iterate on str, but that's very likely optimized away by the compiler anyway.
use a single var to keep the count and then its perfect
Please include more information if this is still an issue after 1 year.
You have typo in your code and it did not work, It should have been '\0' instead of '\n'.
So the following fix works.
I think the spec for ']' differs from the one of this test case. My solution is in Java.
Line
if (token.length()>1) mPlus.remove(mPlus.size()-1);
is redundant and can be removed.
Got the same problem when submitting python code.
How do I handle "Unknown Error"? Help please!
Add Rust too, please!