读写文件

2018-06-17 21:32:31来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

1.读文件

FILE *fp_in = NULL;
fp_in = fopen("test.h264", "rb");
if (!fp_in) 
{
    printf("Could not open input stream\n");
    return -1;
}

unsigned char *in_buffer;
in_buffer = new unsigned char[4096 * 4];

unsigned char *cur_ptr = NULL;
int cur_size = 0;

while (feof(fp_in) == 0)
{
    cur_size = fread(in_buffer, 1, 4096 * 4, fp_in);
    if (cur_size == 0)
        break;

    cur_ptr = in_buffer;

    //input_stream_data(cur_ptr, cur_size) ;

    Sleep(10);
}

fclose(fp_in);

delete[] in_buffer;
in_buffer = NULL;

 

2.写文件

写文件主要为以下:

FILE * outfile;
outfile = fopen("test.h264", "wb" );
if( outfile == NULL )
{
    printf("fopen error");
}   

fwrite( cur_ptr, sizeof( unsigned char ), cur_size, outfile );
    
fclose(outfile);

结合1、2,读写文件一起:

FILE *fp_in = NULL;
fp_in = fopen("test.h264", "rb");
if (!fp_in) 
{
    printf("Could not open input stream\n");
    return -1;
}

FILE * outfile;
outfile = fopen("out.h264", "wb" );
if( outfile == NULL )
{
    printf("fopen error");
} 

unsigned char *in_buffer;
in_buffer = new unsigned char[4096 * 4];

unsigned char *cur_ptr = NULL;
int cur_size = 0;

while (feof(fp_in) == 0)
{
    cur_size = fread(in_buffer, 1, 4096 * 4, fp_in);
    if (cur_size == 0)
        break;

    cur_ptr = in_buffer;

    fwrite( cur_ptr, sizeof( unsigned char ), cur_size, outfile );

    Sleep(10);
}

fclose(fp_in);
fclose(outfile);

delete[] in_buffer;
in_buffer = NULL;

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:hdu_1573_X问题 (分段之中国剩余

下一篇:设计模式----单例模式