Skip to content

Instantly share code, notes, and snippets.

@Sebbyastian
Created February 13, 2015 10:55
Show Gist options
  • Save Sebbyastian/08f98295debb8fe8500d to your computer and use it in GitHub Desktop.
Save Sebbyastian/08f98295debb8fe8500d to your computer and use it in GitHub Desktop.
some_challenge.c
int main(void) {
unsigned char *value = NULL;
size_t size = 0;
for (;;) {
int c = getchar();
if (c == EOF) {
break;
}
size_t s = size + 1;
s &= size;
if (s == 0) {
void *temp = realloc(value, size * 2 + 1);
if (temp == NULL) {
perror("realloc");
exit(EXIT_FAILURE);
}
value = temp;
}
value[size++] = c;
}
puts(value);
while (size-- > 0) {
putchar(value[size]);
}
putchar('\n');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment