码迷,mamicode.com
首页 > 其他好文 > 详细

修改文件内容

时间:2016-05-09 12:36:32      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

修改文件头内容:

  通过使用rb+模式,代码如下:

  

void CfileTestDlg::OnBnClickedButton1()
{

    struct student
    {
        char name [96];
        int   nId ;
        char  desc[1024];

    };

    FILE *fp = fopen("D:\\20080507.log ", "rb+");

    if (fp==0)
    {
        printf("can‘t open file\n");
        return ;
    }

    char szBuf[4096];
    memset (szBuf,0,sizeof(szBuf));
    struct student   stud;
    stud.nId  = 96;
    memcpy(stud.name,"iqaeuqioweuqeruurururuu89999999999999",strlen("iqaeuqioweuqeruurururuu8888888888"));

    memcpy(szBuf, &stud, sizeof(student));

    fseek(fp, 0, SEEK_SET);

    fwrite(szBuf, 4096, 1, fp);
    fflush(fp);
    fclose(fp);
    return ;
}

 

void CfileTestDlg::OnBnClickedButton2()
{
    // TODO: Add your control notification handler code here
    struct student
    {
        char name [96];
        int   nId ;
        char  desc[1024];

    };


    FILE *fp = fopen("D:\\20080507.log ", "a+");

    if (fp==0)
    {
        printf("can‘t open file\n");
        return ;
    }

    char szBuf[4096];
    memset (szBuf,0,sizeof(szBuf));
    struct student   stud;
    stud.nId  = 96;
    memcpy(stud.name,"iqaeuqioweuqeruurururuu8888888888",strlen("iqaeuqioweuqeruurururuu8888888888"));

    memcpy(szBuf, &stud, sizeof(student));

    fseek(fp, 0, SEEK_END);

    fwrite(szBuf, 4096, 1, fp);

    fwrite(szBuf, 4096, 1, fp);

    fflush(fp);
    fclose(fp);
    return ;
}

  函数OnBnClickedButton2:往文件中写入内容

  函数OnBnClickedButton1,修改文件前4096个字符,,,

修改文件内容

标签:

原文地址:http://www.cnblogs.com/fenglangxiaotian/p/5473310.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!