OK, turing.

<- leave blank

Sat Feb 9 22:37:41 EST 2019

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

char* parenflip(char *in) {
	char c;
	char *buf = calloc(1, sizeof(char));
	char *p;
	char *q;
	int l, i;
	int L = 1;
	static char *st;

	for(q = in; ; q++) {
		c = *q;
		if (c == '(') {
			p = parenflip(q+1);
			q = st;
			l = strlen(p);
			buf = realloc(buf, l + L);
			for (i = 0; i < l; i++) {
				buf[L+i-1] = p[l-i-1];
			}
			free(p);
			buf[L+l-1] = '\0';
			L += l;
			continue;
		}
		if (c == ')' || c == '\n' || c == '\0') {
			st = q;
			return buf;
		}
		L++;
		buf = realloc(buf, L);
		buf[L-1] = '\0';
		buf[L-2] = c;
	}
	free(buf);
	return NULL;
}

void main() {
	char *s = malloc(1024);
	char *p;

	while(fgets(s, 1023, stdin) != NULL) {
		p = parenflip(s);
		printf("%s\n", p);
		free(p);
	}
}