我想用文件hdr
中的数据填充(结构)变量,in.wav
并且我想将文件的前 64 个字节复制in.wav
到另一个文件(out.wav
)。
但!第二次使用时,从第一次使用结束的地方fread()
开始复制。为什么?in.wav
fread()
#include <stdio.h>
#include <stdlib.h>
typedef struct FMT
{
char SubChunk1ID[4];
int SubChunk1Size;
short int AudioFormat;
short int NumChannels;
int SampleRate;
int ByteRate;
short int BlockAlign;
short int BitsPerSample;
} fmt;
typedef struct DATA
{
char Subchunk2ID[4];
int Subchunk2Size;
int Data[441000]; // 10 secs of garbage. he-he)
} data;
typedef struct HEADER
{
char ChunkID[4];
int ChunkSize;
char Format[4];
fmt S1;
data S2;
} header;
int main()
{
FILE *input = fopen("in.wav", "rb");
FILE *output = fopen("out.wav", "wb");
unsigned char buf[64];
header hdr;
if(input == NULL)
{
printf("Unable to open wave file\n");
exit(EXIT_FAILURE);
}
fread(&hdr, sizeof(char), 64, input);
fread(&buf, sizeof(char), 64, input);
fwrite(&buf, sizeof(char), 64, output);
printf("\n>>> %4.4s", hdr.ChunkID);
fclose(input);
fclose(output);
return 0;
}
有什么事?