Calling a function poiner

It segfaults because you have not assigned the print pointer. Try this instead:

int main(int argc, char * argv[])
{

    Book book  = {
        .title="Jaws",
        .year=2000,
        .print=print
    };
    print(&book);      // this works
    book.print(&book); // this no longer seg faults
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top