Cardi
Cardi

Reputation: 39

Segmentation fault when create FILE

I try to convert an XML file with XSLT into HTML.

#include <string.h>
#include <libxml/xmlmemory.h>
#include <libxml/debugXML.h>
#include <libxml/HTMLtree.h>
#include <libxml/xmlIO.h>
#include <libxml/DOCBparser.h>
#include <libxml/xinclude.h>
#include <libxml/catalog.h>
#include <libxslt/xslt.h>
#include <libxslt/xsltInternals.h>
#include <libxslt/transform.h>
#include <libxslt/xsltutils.h>

extern int xmlLoadExtDtdDefaultValue;

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

    int i=1;
    const char *params[1];
    xsltStylesheetPtr cur = NULL;
    xmlDocPtr doc, res;
    //FILE * ptrFile;
    //ptrFile = fopen("result.html", "r");

    params[0] = NULL;
    xmlSubstituteEntitiesDefault(1);
    xmlLoadExtDtdDefaultValue = 1;
    cur = xsltParseStylesheetFile((const xmlChar *)argv[i]);
    i++;
    doc = xmlParseFile(argv[i]);
    res = xsltApplyStylesheet(cur, doc, params);
    xsltSaveResultToFile(stdout, res, cur);

    //fclose(ptrFile);

    xsltFreeStylesheet(cur);
    xmlFreeDoc(res);
    xmlFreeDoc(doc);

        xsltCleanupGlobals();
        xmlCleanupParser();

    return(0);

}

It works but HTML code displays in console. I want to save it into a file but when I try to create file "result.html" and put it into xsltSaveResultToFile(ptrFile, res, cur) there is an error "segmentation fault". Wahat should I do to fix it?

Upvotes: 0

Views: 100

Answers (0)

Related Questions