Created
February 13, 2015 10:55
-
-
Save Sebbyastian/08f98295debb8fe8500d to your computer and use it in GitHub Desktop.
some_challenge.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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