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

Optimized version of leftpad in plain C

Name: Anonymous 2016-03-23 21:32

#include <string.h>

static const char*
string_add(const char* first, const char* second)
{
const char* result = malloc(strlen(first) + strlen(second) + 1);
strcat(result, first);
strcat(result, second);
return result;
}

const char*
leftpad(const char* str, size_t len, char ch)
{
int i = -1;

if (ch == 0) ch = ' ';

int len = strlen(str);

while (++i < len) {
char buf[2] = { 0 };
buf[0] = ch;
str = string_add(buf, str);
}

return str;
}

Name: Anonymous 2016-04-18 8:00

>>83
Fuck you. I do a lot of imaging old software & docs, and systems should have knowledge of all the shitty old encodings for when you need them. It's not like they take any considerable space or slow anything down.

All you backwards fucknuts need to have the machine fucking working for you, instead of trying to let the machine off the hook for complex cases. Are you dickheads are afraid of computing? This is what computers are for!

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