Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7008913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:47:46+00:00 2026-05-27T21:47:46+00:00

I wrote this program in C and also in erlang To practice I tried

  • 0

I wrote this program in C and also in erlang

To practice I tried to rewrite in D. A friend also wrote it in D but wrote it differently

The steps are simple. Pseudocode:

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

My D attempt:

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);
  }   
}

It seems I can’t just use fread on arr. sizeof is 16 and it gives segmentation fault when I get to the subtracting part. I can’t auto alloc a static array, or at least I don’t know how. I also can’t seem to use malloc because it gives me errors when I try to cast the void* when I loop through the bytes. How would you write this, or, what could I do better?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:47:47+00:00Added an answer on May 27, 2026 at 9:47 pm

    again why do you expect to be able to read in the entire chunk into a single array (which size in bytes fits in a 64 bit long (possibly more that several petabytes) I made that comment in the other question as well

    use a loop to copy the contents

    writeln("start");
    x=swapEndian(x);
    writeln(x," ",cnt++,"\n");
    ubyte[1024*8] arr=void; //the buffer 
                //initialized with void to avoid auto init (or declare above the for)
    ubyte b; //temp buff
    File out = File("/home/fold/wak_oggs/"~to!string(cnt)~".ogg", "wb");
    
    b=fp.rawRead(arr[0..x%$]);//make it so the buffer can be fully filled each loop
    foreach(ref e;b)e-=1;//the subtract 1 each byte loop
    out.rawWrite(b);
    x-=b.length;
    while(x>0 && (b=fp.rawRead(arr[])).length>0){//loop until x becomes 0
        foreach(ref e;b)e-=1;
        out.rawWrite(b);
        x-=b.length;
    }
    

    I’m using rawRead and rawWrite to read and write

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this simple Prolog program. man(socrates). mortal(X) :- man(X). immortal(X) :- immortal(X). I
Ok, i wrote 2 versions of this program. But im looking for the best
I wrote a program that uses builtin function bin(), but this function is new
I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to
I wrote a program to solve a complicated problem. This program is just a
I wrote a basic Hippity Hop program in C, Python, and OCaml. Granted, this
I wrote this snippet of code and I assume len is tail-recursive, but a
I wrote a small test program with a sample class containing also self-defined constructor,
Is this normal, or is there something weird with my program?: i wrote a
I wrote a Linux program based on a buggy open source library. This library

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.