Ad
  • Default User Avatar

    Please use markdown to post your code next time ;-)

    • you return a string literal if n == 0: you need to return a malloc()'ed string in each case. This is why the tests crash: they try to free() your returned string, but a string literal cannot be freed.

    Other mistakes:

    • your loop counter i starts at 1, but you print i + 1 to the string, so 1 sheep... is missing
    • your memory allocation is not very robust: if n == 10000, "10000 sheeep..." will be 15 characters long, but you allocate only 13 for mur and 13 * n for murmur ---> for large n you will run out of memory and write out-of-bounds
  • Default User Avatar

    look at the length and the individual bytes of your string - it does not work perfectly, you are not measuring correctly. granted, I can see how that would be confusing, but, it also seems like the sort of thing to watch out for in C with all the footguns available