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

Hey Leute!

Habe da ein Problem und zwar möchte ich gerne eine char variable abfragen!

Hier ein kleines test programm:

#include <iostream.h>

int main ()

{

char a[2];

cout<<"Einen Buchstaben eingeben: ";

cin>>a;

cout<<"eingabe: "<<a<<endl;

if (a == "j")

{

cout<<"test";

}

else

{

cout<<"test3";

}

}

Jetzt sollte er meiner Meinung hin gehen und wenn man ein kleines j eingibt, das

er dann Test ausgibt! Doch er gibt immer test3 aus! Jetzt meine Frage: Warum?

Und wie kann man sie richtig abfragen?

Danke schonmal!

Morgen!

Probiers mal mit

if (a[0] == 'j')

Aber warum macht du ein char-Array, wenn du einen Buchstaben einlesen und abfragen willst?

mach doch einfach:

char a; und a=='j'

Originally posted by dgorski

if (a == "j")

Was Du hier machst, ist ein Adressvergleich. Die Adresse des Stringliterals "j" vergleichst Du mit der Adresse des ersten Elements von a.

<Gebetsmühle>

char-Strings vergleicht man mit strcmp. Achtung, strcmp gibt bei Übereinstimmung Null zurück.

</Gebetsmühle> ;)

Falls Du wirklich nur ein einziges Zeichen vergleichen willst, solltest Du HELLmuts Vorschlag verwenden.

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.