How to avoid segmentation fault in a buffer overflow exploit

I have an excersise of making a buffer flow exploit for directing a function insinde another function without calling it. First I need to print “now inside entrance()” then print “now inside secret()”

I was able to print “now inside secret()” by overflowing the buffer via assingning above address of doNotTouch which is return address of entrance function. But now I am getting a segmentation fault, which I shouldn’t have.

I am doing this exercise on a x86_64 Debian system and gcc verison 4.9. I am prohibited to call any function or editing outside the given area in entrance(). I also shouldn’t compile with compile options.

Thanks in advance

 #include <stdio.h>

void secret()
{
    printf("now inside secret()!n");
}

void entrance()
{
int doNotTouch(4);
// can only modify this section BEGIN
// cant call secret(), maybe use secret (pointer to function)

*(doNotTouch + 6) = &secret;

// can only modify this section END
printf("now inside entrance()!n");

}

int main (int argc, char *argv())
{
    entrance();
    return 0;
}