I wrote this program in C也in erlang写这个的方法是什么?
为了实践我试图D.重写一个朋友还写它d但wrote it differently
步骤很简单。伪代码:
While not end of file:
X = Read ulong from file and covert to little endian
Y = Read X bytes from file into ubyte array
subtract 1 from each byte in Y
save Y as an ogg file
我d尝试:
import std.file, std.stdio, std.bitmanip, std.conv, core.stdc.stdio : fread;
void main(){
auto file = File("./sounds.pk", "r+");
auto fp = file.getFP();
ulong x;
int i,cnt;
while(fread(&x, 8, 1, fp)){
writeln("start");
x=swapEndian(x);
writeln(x," ",cnt++,"\n");
ubyte[] arr= new ubyte[x];
fread(&arr, x, 1, fp);
for(i=0;i<x;i++) arr[i]-=1;
std.file.write("/home/fold/wak_oggs/"~to!string(cnt)~".ogg",arr);
}
}
看来我不能只用FREAD上ARR。 sizeof是16,当我到达减法部分时它给出了分段错误。我不能自动分配一个静态数组,或者至少我不知道如何。我也似乎无法使用malloc,因为当我尝试在通过字节循环时抛出void *时,它会给出错误。你会如何写这个,或者,我能做得更好?
确定'&arr'指向数组的第一个元素? – hvd 2012-01-02 23:52:41