On 13.12.2016 23:30, Ali wrote:
Hi, Long time watcher and recently started playing with D a bit more.
Ran in to a couple of snags that I'll combine in one post. It involves a
data set that contains a list of strings. Each string represents a Room
name. What I'm trying to do is pluck out the room names and also
calculate the frequency each letter occurs in a name, per room.

First problem is to do with pointers to structs. Here's the code:

static immutable rooms = import("data.txt").split("\n").map!parse.array;

static Tuple!(const(Room*), "room", int[char],
"frequencies")[rooms.length] data;
static this() {
     foreach (i, room; rooms) {
         data[i].room = &room;
         // Also calculate frequencies, but that's not important yet.
     }
}

void main() {
     foreach (d; data) {
         d.room.name.writeln; // <-- How do I access name here??
     }
}

I've tried d.(*room).name but that didn't work. There's no arrow
I'm sleepy, sorry for quick and probable wrong answer - try (*d.room).name

  • ... Ali via Digitalmars-d-learn
    • ... drug007 via Digitalmars-d-learn
      • ... Ali via Digitalmars-d-learn
        • ... bauss (wtf happend to my name took some old cached title LOL??) via Digitalmars-d-learn
    • ... Ali Çehreli via Digitalmars-d-learn
      • ... Ali via Digitalmars-d-learn
        • ... Ali Çehreli via Digitalmars-d-learn
          • ... Ali via Digitalmars-d-learn
            • ... Ali Çehreli via Digitalmars-d-learn
              • ... Stefan Koch via Digitalmars-d-learn
                • ... Ali Çehreli via Digitalmars-d-learn
                • ... Ali via Digitalmars-d-learn

Reply via email to