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.

Empfohlene Antworten

Veröffentlicht

Hallo,

ich hätte folgende Frage:

Wie schaffe ich es einen Wert aus einem String Array in ein Char Array zu kopieren, um dass dann zum Vergleich zu übergeben?

Hier mal der Code zum besseren Verständnis:


{

string wort[20];

chr *wortarray[20];

.

.                  //Hier wird das String Array mit Wörtern aus einer Datei gefüllt

.

//Hier sollte dann der String in das Wortarray kopiert werden, um dann mit qsort sortiert zu werden


qsort(wortarray,20,sizeof(char*), compare); //Aufruf von qsort

}

int compare(const void* left, const void* right)

{

        return strcmp(*(char**)left,*(char**)right);

}

Danach soll das sortierte char Array wieder ins String Array geschrieben werden. Wer kann mir, bitte, bitte, bitte, helfen???? Ramme schon seit 3h den Kopf gegen den Tisch, hat aber leider noch nix gebracht. Mein erster Versuch war:

int z2=0;

do

{

 wortarray[z2]=wort[z2];

 z2++;

}while(z2==19);

Benutzt std::sort denn den Quicksort Algorithmus?
Wenn nicht, dann etwas besseres. Neuere Implementierungen benutzen üblicherweise einen Algorithmus, der auch im Worst case O(n log n) hat. Da das eine Templatefunktion ist, kannst du dir den Quellcode ansehen.

#include <algorithm>

string wort[20];
std::sort(wort, wort+20);[/code]

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

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.