Dynamisches Array erzeugen
-
Hi Leute,
würde gerne daß Array "Werte" dynamisch erzeugen lassen. Und zwar mit der Anzahl die ich der Variable "zahlenanzahl" aus meinem Edit zuweise. Habe daß mal wie es unten steht probiert, klappt so aber leider nicht. Würde gerne eure Hilfe bekommen.Danke
yellow1
double zahlenanzahl = StrToFloat(Form1->edZahlenanzahl->Text);
werte = new double[zahlenanzahl];
werte[zahlenanzahl];
-
Hallo,
da wir hier im C Forum sind, wirst du wohl eher malloc brauchen:
size_t anzahl=0; scanf("%d", &anzahl); double *array = (double*)malloc(sizeof(double) * anzahl)); //mit array arbeiten free(array);
-
in c++ geht das so:
int zahlnenzahl=StrToInt(Form1->edZahlenanzahl->Text); double *werte = new[zahlenanzahl] double;der arrayindex muß eine ganzzahl sein.
-
Konfusius schrieb:
in c++ geht das so:
int zahlnenzahl=StrToInt(Form1->edZahlenanzahl->Text); double *werte = new[zahlenanzahl] double;der arrayindex muß eine ganzzahl sein.
- falsches forum
- falscher code
double *werte = new double[zahlenanzahl];wäre richtig
-
Dieser Thread wurde von Moderator/in c.rackwitz aus dem Forum ANSI C in das Forum C++ verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.