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.

Mysql - Integer vergleichen

Empfohlene Antworten

Hallo,

ich versuche einen Integer zu vergleichen, aber es kommt die Warnung: "Warnung: Vergleich zwischen Zeiger und Ganzzahl" und es wird bei folgendem code "test3" ausgegeben, obwohl "test1" ausgegeben werden sollte.

Code:

mysql_real_query(my, STR, strlen(STR));

res = mysql_store_result (my);


while ((row = mysql_fetch_row (res)) != NULL) {

  if (row[5] == 1) {

      printf ("test1");

    }

    else if (row[5] == 2) {

      printf ("test2");

    }

    else

      printf ("test3");

}
In dieser Mysql Spalte steht die Zahl 1 und der typ der Spalte ist Int(1). Wenn ich über
printf ((char *) row[5]);
das ausgeben lasse, gibt er die 1 aus. Aber wenn ich die Abfragen entsprechend anpasse:
mysql_real_query(my, STR, strlen(STR));

res = mysql_store_result (my);


while ((row = mysql_fetch_row (res)) != NULL) {

  if ((char *) row[5] == "1") {

      printf ("test1");

    }

    else if ((char *) row[5] == "2") {

      printf ("test2");

    }

    else

      printf ("test3");

}

kommt immer noch "test3" raus (aber ohne Warnung).

Woran kann dies liegen?

ups

Ich danke dir. Das kommt davon, wenn man nur ein bisschen C kann und dann noch mit anderen Programmier-/Skriptsprachen zu tun hat.

Hallo,

alternativ kannst Du natürlich auch mittels "atoi" in einen Integer konvertieren:

mysql_real_query(my, STR, strlen(STR));

res = mysql_store_result (my);


while ((row = mysql_fetch_row (res)) != NULL) {

  if (atoi(row[5]) == 1) {

      printf ("test1");

    }

    else if (atoi(row[5]) == 2) {

      printf ("test2");

    }

    else

      printf ("test3");

}

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.