我们可以使用c写入word文件吗?

zee*_*zee -1 c file docx

int main()
{
    FILE *fs,*ft;
    char ch;
    fs=fopen("main.c","r");
    if(fs==NULL)
    {
        printf("can not open source file\n");
        getch();
        exit(1);
    }
    ft=fopen("demo.docx","w");
    if(ft==NULL)
    {
        printf("can not open target file\n");
        getch();
        exit(1);
    }
    while(1)
    {
        ch=fgetc(fs);
        if(ch==EOF)
        {
            break;
        }
        fputc(ch,ft);
    }
    fclose(fs);
    fclose(ft);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

使用上面的代码,我试图将内容复制main.cdemo.docx.
该程序工作正常,但当我外部打开时demo.docx,它崩溃了.
我身边有问题,或者我们无法docx使用c 写入文件?

jpw*_*jpw 7

Word文档不像普通文本文件那样编写,而是以非常特定的格式编写,您必须遵循这些格式.这当然可以在C中完成,但我强烈建议不要使用它,而是尝试找到一些要使用的库或使用不同的语言和框架.C#/ .Net和Java都有很好的选择来处理Office文档(例如,对于Java,有Apache POI).

如果你真的想浪费你的时间,你可以在这里找到Office文件的规范:http://msdn.microsoft.com/en-us/library/cc313105%28v=office.12%29.aspx