首页 > 其他 > 详细

文件操作

时间:2016-09-22 21:20:43      阅读:89      评论:0      收藏:0      [点我收藏+]
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"

static int GetFileSize(FILE *stream)
{
    int curPostion;
    int length;
    curPostion = ftell(stream);
    fseek(stream, 0L, SEEK_END);
    length = ftell(stream);
    fseek(stream, curPostion, SEEK_SET);
    return length;
}

int _tmain(int argc, _TCHAR* argv[])
{
    FILE    *fpIn;
    char    *p_buf;
    int     file_size;
    int     length;
    //if (argc != 2)
    //{
    //    printf("Error format,Usage: display filename1\n");
    //    return 0; //键入了错误的命令行,结束程序的执行
    //}
    //if ((fpIn = fopen(argv[1], "r")) == NULL)
    //
    if ((fpIn = fopen("C:\\Users\\liu\\Desktop\\MCS1\\Turbo_decoding_Ue1_Sym2.dat", "r")) == NULL)
    {
        printf("file open err!\n");
        exit(1);
    }
    else
    {
        file_size = GetFileSize(fpIn);
    }

    p_buf = (char *)malloc(file_size);
    length = fread(p_buf, sizeof(char), file_size, fpIn);
    p_buf[length] = 0;

    printf("File Size : %d\n", file_size);
    printf("Read Size : %d\n", length);

    printf("%s\n", p_buf);
    system("pause");
    return 0;
}

 

文件操作

原文:http://www.cnblogs.com/alexliu2360/p/5897796.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!