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

文件操作

时间:2016-09-22 21:22:47      阅读:169      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!