首页 > 代码库 > 文件操作

文件操作

#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;}

 

文件操作