Well, the same idea, but we have one queue and a hash table now!

Full source code at GitHub.

char* fractionToDecimal(long numerator, long denominator)
{
unsigned long long n = llabs(0ULL | numerator);
unsigned long long d = llabs(0ULL | denominator), r = 0, q = 0;
int off = 0, sign = 0, st, en, doff, f = 0, count = 0;
void *hasht = NULL, *fqueue = NULL;
char *dec = NULL;
struct ValCount {
unsigned long long val;
int count;
};
struct ValCount *b = NULL;
struct ValCount v;
/* Validate */
if (!denominator || ((hasht = HashTAlloc(QUEUE_SZ,
sizeof(struct ValCount), HashGen, HashCmp)) == NULL) ||
((fqueue = QueueAlloc(QUEUE_SZ, sizeof(int))) == NULL))
return NULL;
/* Figure out the sign */
if (numerator < 0) sign = 1;
if (denominator < 0 && n != 0)
sign = (sign == 0 ) ? 1 : 0;
/* Get the quotient */
q = n / d;
/* Check if there is a remainder */
while ((r = (n % d)) && b == NULL){
/* Multiply by 10 */
n = r * 10ULL;
/* Search for the value. If the value not present,
then add it to the hash table. */
if ((b = HashTSearch(hasht, &n)) == NULL) {
v.val = n;
v.count = count++; // counter to track '('
if (HashTAdd(hasht, &v))
goto __exit;
/* Add fraction digit to the queue */
f = (int)(n / d);
if (QueueAdd(fqueue, &f))
goto __exit;
}
}
/* Allocate the return character array */
dec = malloc(sizeof(char) * (QueueSzGet(fqueue) + 32));
if (!dec) goto __exit;
/* If needed, add the sign */
if (sign) dec[off++] = '-';
/* Generate the quotient string */
while (q > 9){
dec[off++] = INT_TO_ASCII(q % 10);
q /= 10;
}
dec[off++] = INT_TO_ASCII(q % 10);
/* We need to reverse the quotient string. */
st = sign;
en = off - 1;
while (st < en)
SwapChars(&dec[en--], &dec[st++]);
/* If the fraction part is present, then add the same */
if (QueueSzGet(fqueue)) {
dec[off++] = '.'; // add decimal point
doff = off; // save the starting offset of the fraction
/* Now generate the fractional part */
while (!QueueDel(fqueue, &f)) {
if (b && off - doff == b->count) // place braces at the correct offset
dec[off++] = '(';
dec[off++] = INT_TO_ASCII(f);
}
/* Mark closing braces */
if (b != NULL)
dec[off++] = ')';
}
dec[off] = 0; // NULL termination
__exit:
if (hasht) HashTFree(hasht);
if (fqueue) QueueFree(fqueue);
return dec;
}