Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

2010 Homework No. 3 - findsuss

Name: Anonymous 2010-01-15 22:56

Write a program in the language of your choice that takes a string and inputs "SUSSMAN" for every time those characters appear. In case I'm not being clear, that means output "SUSSMAN" for every 3 's's and 1 'u', 'm', 'a', and 'n' in the string. Inputting "ssssumanssssssssssuman", for example, would print "SUSSMAN" twice. "ssuman", however, would print nothing.

I've written an inelegant solution in C, which I'll post in a second. It tends to crash after execution, however, and I cannot for the life of me figure out what I'm doing wrong. It does everything it's supposed to but refuses to terminate politely. Even stranger, it only happens when there is enough characters for two or more sussmen. I guess the problem is in the susscount loop, but I can't figure out where. Mind giving me a hand, /prog/?

Name: Anonymous 2010-01-16 2:40

>>17
What is your definition of a variable length array? You can just malloc your array as you please. The array size is static, but you can extend(re-alloc) the array if needed. Some C functions are unsafe as they can write to a buffer without having a way to control how much they would write, or if they should re-allocate a new buffer. IMO, it's much simpler and safer if the callee allocates the buffer for you and maybe provides some length metadata on the side. It's possible to design safe APIs for C and use C safely, but the coder needs to make a conscious effort to do so. (Or the coder could just use something more high-level than C...)

Name: Anonymous 2010-01-16 3:38

>>17
Protip: C doesn't have variable length arrays
Yes, it does.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List