小编zee*_*zee的帖子

修改c中文件的现有内容

int main()
{
    FILE *ft;
    char ch;
    ft=fopen("abc.txt","r+");
    if(ft==NULL)
    {
        printf("can not open target file\n");
        exit(1);
    }
    while(1)
    {
        ch=fgetc(ft);
        if(ch==EOF)
        {
            printf("done");
            break;
        }
        if(ch=='i')
        {
            fputc('a',ft);
        }
    }
    fclose(ft);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

正如我可以看到的那样,我想以abc.txt一种i被其替换的方式进行编辑a.
该程序工作正常,但当我在abc.txt外部打开时,它似乎是未经编辑的.
任何可能的原因?

为什么在这种情况下,后面的字符i不会被替换a,如答案所示?

c edit file-handling

6
推荐指数
1
解决办法
4万
查看次数

为什么我们不能在结构中声明函数?

我读了很多关于的问题

declaration of functions inside structure?

但我没有得到满意的答案.

我的问题不在于此 whether functions can be declared inside a structure or not?

相反,我的问题是

WHY function can not be declared inside structure?

c struct declaration function

2
推荐指数
1
解决办法
1万
查看次数

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

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 写入文件?

c file docx

-1
推荐指数
1
解决办法
1220
查看次数

标签 统计

c ×3

declaration ×1

docx ×1

edit ×1

file ×1

file-handling ×1

function ×1

struct ×1