Ver originalbuffer = (char*)realloc(buffer, i+2 ); // sizeof(char) es 1 buffer[i] = c;buffer[i+1] = 0; // <-- agregar esto