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.

Pointer-Aufgabe

Empfohlene Antworten

Veröffentlicht

Guten Tag

Ich bräuchte bitte eine erkärung für nachfolgendes Programm, da ich mich überhaupt nicht auskenne:

#include <stdio.h>

#include <stdlib.h>

int main(int argc, char *argv[])

{

printf("\n Pointer by chris.\n");

start: printf("\n");

// Variablen

// A

int i=0, k=0, laenge=0, n=1, i1=1,*pzwischen, i2=2;

char name[64],text[64];

char merker[2];

char ptr1, ptr2, *ptrtext;

printf("i1 = %d Adresse von i1 ist %p \n",i1, &i1);

printf("i2 = %d Adresse von i2 ist %p \n",i2, &i2);

printf("Abstand Integer: %d",((int)&i1 - (int)&i2));

printf(" || Abstand Adresse: %p \n",(&i1 - &i2));

pzwischen = &i1;

printf("Adresse auf die der Pointer zeigt: %p \n", pzwischen);

// 5a

*pzwischen = 5;

printf("neuer Wert von i1: %d \n", i1);

pzwischen = &i2;

// 5b

printf("neuer Wert von i2 via Pointer: %d \n", *pzwischen);

// C

printf("\nName eingeben.\n");

gets(name);

strcpy(text,name);

printf("\nHallo %s\n",name);

for (laenge=0; name[laenge] != '\0'; laenge++) { ; }

printf("\nLaenge: %d\n Ihr Name wird nun Sortiert.\n",laenge);

// B

n=1;

k=0;

while (n)

{

n=0;

for (i=0;i < (laenge-1); i++)

{

if (text > text[i+1])

{

merker[1]=text;

text=text[i+1];

text[i+1]=merker[1];

n++;

k++;

}

}

}

printf("\nsortiert: %s\n",text);

printf("Sortierungen: %d\n Nun wird das ganze nochmals mit Pointer sortiert. \n",k);

strcpy(text,name);

n=1;

k=0;

ptrtext=text;

while (n)

{

n=0;

for (i=0;i < (laenge-1); i++)

{

if (ptrtext > ptrtext[i+1])

{

merker[1]=ptrtext;

ptrtext=ptrtext[i+1];

ptrtext[i+1]=merker[1];

n++;

k++;

}

}

}

printf("\nsortiert: %s\n",text);

printf("Sortierungen: %d\n Fertig \n",k);

printf("\n");

ende: printf("\n Ende \n");

system("PAUSE");

return 0;

}

Meine Frage ist was das Programm macht und wiso es das macht

Danke schon mal im vorraus.

Hi,

zu Anfang macht es gar nichts, weil die Bibliothek string.h fehlt.

Das Programm fordert dich dazu auf deinen Namen einzugeben und anschließend werden die Buchstaben dem Alphabet nach sortiert.

Um alles Schritt für Schritt nachvollziehen zu können, würde ich dir raten den Debugger zu nutzen.

Gruß

Jogibaer0411

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.