Ad
  • Default User Avatar

    I think it's because basic tests are hardcoded, the strings are contained in the program, while all the other tests' input lives in local variables on the stack which gets filled with random data each time, then used, then abandoned. You're modifying the program's own memory (data segment, IINM, or maybe rodata, I dunno). Here is a problem: the word "commas" appears in the basic tests more than once. (edit: so does "javascript")The compiler is only going to store that string one time in one place and refer to it multiple times, but you can only "use" it and pass the first time. After that, it's been mangled, and nothing matches, and you are out of luck.

    Many tests on this site will fail because of people modifying the inputs, even when they aren't declared const. If you do see const, don't try it, don't even hope to get away with changing things behind it. If you really feel you need to modify input data (and this time you really don't), just take a copy of it using strdup() and work on that. I tried removing the const qualifiers from my function, and basic tests keep working because I only count the letters.

    P.S. if you use strdup() don't forget to free() that variable when you're done.