新手请教C编程问题,非常感谢!
编写了一段程序,想把一个文件中的数据重新写入另一个文件,数据存放的顺序有所不同,程序编译没有什么问题,但一运行就有问题,请大家帮忙看看,非常感谢!#include <stdio.h>
#include <stdlib.h>
#define WIDTH 720
#define HEIGHT 576
void main()
{
FILE *fp1, *fp2;
int *frame;
int *pointer_Y, *pointer_Cb, *pointer_Cr;
int frameSize, Y_size, Cb_size, Cr_size;
int fth;
int pixel;
int i_Y=0, i_Cb=0, i_Cr=0;
int buffer;
frameSize = 2*WIDTH*HEIGHT;
Y_size = frameSize/2;
Cb_size = Y_size/2;
Cr_size = Cb_size;
pointer_Y = malloc(Y_size);
pointer_Cb = malloc(Cb_size);
pointer_Cr = malloc(Cr_size);
if((fp1=fopen("original.yuv","rb")) == NULL)
printf("Original file open error.\n");
if((fp2=fopen("target.yuv","wb")) == NULL)
printf("Target file open error.\n");
frame = malloc(frameSize);
for(fth=0;fth<100;fth++)
{
fread(frame,1,frameSize,fp1);
for(pixel=0;pixel<frameSize;pixel++)
{
buffer = pixel%4;
switch(buffer)
{
case 0:
{
*(pointer_Cb+i_Cb) = *(frame+pixel);
i_Cb++;
}
case 1:
{
*(pointer_Y+i_Y) = *(frame+pixel);
i_Y++;
}
case 2:
{
*(pointer_Cr+i_Cr) = *(frame+pixel);
i_Cr++;
}
case 3:
{
*(pointer_Y+i_Y) = *(frame+pixel);
i_Y++;
}
}
}
fwrite(pointer_Y,1,Y_size,fp2);
fwrite(pointer_Cb,1,Cb_size,fp2);
fwrite(pointer_Cr,1,Cr_size,fp2);
}
fclose(fp1);
fclose(fp2);
}