也是网上看到的,忘记在哪儿看到的了。
去掉头44字节。
#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *infile, *outfile;
char *buf = NULL;
long length;
if((infile = fopen ("e:\\1.wav", "rb+"))==NULL)
{
printf("Open the 1.wav failed\n");
return ;
}
else
{
printf("Open the 1.wav success\n");
}
if((outfile = fopen ("e:\\2.pcm", "wb"))==NULL)
{
printf("Open the 2.pcm failed\n");
return ;
}
else
{
printf("Open the 2.pcm success\n");
}
//infile文件位置移动到末尾
fseek(infile, 0, SEEK_END);
//获得infile文件含有的字节数
length = ftell(infile);
//文件数据段长度等于文件总长度-文件头长度位置
buf = (char*)malloc(length-43);
//0~43字节为wav的头部信息,移动到44的位置
fseek(infile, 44, SEEK_SET);
//复制wav文件length-44个单位字节到buf中,每个单位为1字节
fread(buf, 1, length-44, infile);
//文件数据段长度为a-44,但指针是指向前一个指针
fwrite(buf, 1, length-44, outfile);
free(buf);
fclose(infile);
fclose(outfile);
}