3 ms·
That seems pretty poor. I'm a pretty crappy programmer and haven't written any C in 18 years, but despite tripping over my feet for fifteen minutes, I have a wo
by petercooper 16y ago
That seems pretty poor. I'm a pretty crappy programmer and haven't written any C in 18 years, but despite tripping over my feet for fifteen minutes, I have a working 4 line function. I despair for what passes as a professional programmer in shops that don't bother to check their people out properly..
Added: In the interests of "put up or shut up": http://gist.github.com/415975 http://gist.github.com/415975 - no idea if it's OK by today's standards but hey, it works
- sethg 16y agoThe program also seems to work if, in the loop header, you replace “i <= strlen(z_terminated)” with “z_terminated[j] != 0”. I don’t understand why I have to put j in the index there, rather than j-1: after the string-ending null is copied, j is incremented, right?
- studer 16y agoWell, if you don't understand your own code, it's probably not a good idea to write it that way (for-loops are a lot easier to read & verify if the stop condition depends on the loop variable, for example). But your solution isn't just hard to read, it's also horribly broken. If you cannot figure out why, try printing the value of 'i' inside the loop.
- nkurz 16y agoI don't think 'j' nor 'j-1' would make sense here. 'i' would make sense, if you also terminate the condensed string. Maybe it would be clearer if the names of the index variables better described their purpose? http://gist.github.com/416298 http://gist.github.com/416298 (no peaking if you're submitting!) I think these names make it clearer that neither "z_terminated[condensed]" nor "z_terminated[condensed - 1]" are reliable ways to find the end of the original string.