文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>C语言实例58:fwrite()和fread()

C语言实例58:fwrite()和fread()

时间:2010-07-04  来源:hnrainll

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    FILE *fp;
    int i = 156;
    long l = 9701076L;
    double d = 3.456;

    if((fp = fopen("test.txt","w")) == NULL)
    {
    printf("不能打开文件.\n");
    exit(0);
        }

    fwrite(&i, sizeof(int), 1, fp);
    fwrite(&l, sizeof(long), 1, fp);
    fwrite(&d, sizeof(double), 1, fp);

    rewind(fp);

    fread(&i, sizeof(int), 1, fp);
    fread(&l, sizeof(long), 1, fp);
    fread(&d, sizeof(double), 1, fp);

    printf("i = %d\n", i);
    printf("l = %ld\n", l);
    printf("d = %f\n", d);

    fclose(fp);
    system("pause");
    return 0;
}


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载