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.

Arbeiten mit Zeichen

Empfohlene Antworten

Veröffentlicht

Code:



#include<stdio.h>


int main()

{

  int i,j;

  char ch;

  for (i=0; i<16;i++)

  {

    for (j=0; j<8; j++)

    {

      ch = i + 16 *j;

  if (ch >=32 && ch <=126)

    printf(" %X %c",ch,ch);

   else

   printf(" %X %c", ch,' ');

  }

  printf("\n");

}

 return 0;

}	

In diesen Programm verstehe ich eine Zeile nicht und zwar die hier : Code:
ch = i + 16 *j;	

Was wird hier getan ?

Bitte um Hilfe und danke im voraus.

mfg soufian

Hallo soufian!

Nun, im Prinzip ganz einfach: Der Variablen ch wird ein Wert zugewiesen, der aus dem 16-fachen von j plus i besteht.

Das ch eine char-variable ist, stört weiter nicht, da char = 8bit integer.

Bei der Ausgabe wird ch als Zeichen interprätiert, also entspricht i + 16 *j dem Ascii-Wert des Zeichens. So kann man das selbe auf zwei verschiedene Weisen ansprechen :)

Etwas verwirrend :upps , aber irgendwann sehr praktisch, wenn man der passende Groschen gefallen ist.

tsg

heißt dann die Zeile auch :

16+16*8 

?

wenn ich aber die Zeile ändere das es so aussieht:

#include<stdio.h>


int main() 

{ 

  int i ,j;

  char ch;

  for (i=0; i<16;i++)

  {

    for (j=0; j<8; j++) 

    {

[SIZE="6"]      ch = 15 + 16*7;[/SIZE]

  if (ch >=32 && ch <=126)

    printf(" %X %c",ch,ch);

   else

   printf(" %X %c", ch,' ');

  }

  printf("\n");

}

 return 0;

}

kommt dann ein etwas verändertes Ergebnis

Ich meine damit sollte es nicht die gleiche Wirkung haben wie das

i + 16*j

?

weil i = 15

und j = 7

Ich dank dir für die Erklärung.:)

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.