Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Array/Matrix Über-/Ausgabe fehlerhaft

Empfohlene Antworten

Hallo,

ich habe ein kleines Problem und suche immer noch des Rätsels Lösung. Und zwar erstelle ich vier Arrays aus einer Matrix mat[r][c] mit r für die Reihe und C für die Spalte. Jedes Array soll dann die Spalte dieser Matrix in sich haben. Jedoch wirft mir der Abruf dieses Arrays nur die letzte eingetragene Spalte aus.

Zeig das mal am Code:

void Matrix::sort_matrix(){

for (int r = 0 ; r < row ; r++){

SpalteA[r]= mat[r][0];

//cout << A[r]<< " " << mat[r][0]<<"\n";

}

for (int s = 0 ; s < row ; s++){

SpalteB= mat[1];

//cout << B<< " " << mat[1]<<"\n";

}

for (int t = 0 ; t < row ; t++){

SpalteC[t]= mat[t][2];

//cout << C[t]<< " " << mat[t][2]<<"\n";

}

for (int v = 0 ; v < row ; v++)

cout << SpalteA[v] << " ";

cout << "\n";

for (int u = 0 ; u < row ; u++){

SpalteD= mat[3];

//cout << D<< " " << mat[3]<<"\n";

}

}

So wenn jetzt die Spalte A nach der dritten Zuweisung abrufe, zeigt er mir aber die SpalteC. Ich denke, das irgendetwas mit der Zuweisung falsch läuft!

Kann mir jemand helfen und mir meinen Fehler aufdecken?!

Gruss und Dank Jimmie

Ich denke, das irgendetwas mit der Zuweisung falsch läuft!
Und ich denke, dass du mindestens eins der Arrays zu klein angelegt hast. Zeig doch mal die Deklarationen. Und welchen Wert hat row?

Und überhaupt: Warum packst du das nicht alles in eine Schleife?

void Matrix::sort_matrix(){ 
for (int r = 0 ; r < row ; r++){
SpalteA[r]= mat[r][0];
SpalteB[r]= mat[r][1];
SpalteC[r]= mat[r][2];
SpalteD[r]= mat[r][3];
}
}
[/code]

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.