Problem mit malloc

#863042
Lesenswert?

1
(double *)malloc((WIDTH*HEIGHT*4));

Und das gewöhn dir mal ganz schnell ab, das ist fehlerträchtig und wie 
man sieht hast du den Fehler auch gleich gemacht.

So schaut's gut aus:
1
(double *)malloc(WIDTH*HEIGHT*sizeof(double));

Ein double hat übrigens 8 Byte...
Gast #863125
Lesenswert?

Wenn du das zweidimensionale Array tatsächlich dynamisch anlegen
willst, geht das so:
1
  double (*workarray)[HEIGHT] =
2
    (double (*)[HEIGHT])malloc(WIDTH*HEIGHT*sizeof(double));

Hinterher kannst du dann in gewohnter Weise mit
1
  workarray[x][y]

darauf zugreifen.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren