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 zusammen!

Ich hab da n kleines Prob...und zwar habe ich folgendes Beispiel aus "C von Anfang an" im KDevelop 2.1 unter Suse Linux 8.0 eingegeben und bekomme vom Debugger die Fehlermeldung : "the 'gets' function is dangerous and should not be used." Bin nu ich doof, der Compiler oder der Author von dem Buch? :rolleyes:

/* bspl0037.c */

#include <stdio.h>

#include <string.h>

main() {

char satz[80];

printf("\nBitte einen Satz eingeben\n>");

gets(satz);

printf("\n%s",satz);

printf("\nDer Satz besteht aus %i Zeichen.",strlen(satz));

printf("\n\nsatz[5] enthaelt eine binaere Null.\n");

satz[5]='\0';

printf("\n%s",satz);

printf("\nDer Satz besteht aus %i Zeichen.",strlen(satz));

}

Die Meldung des Compilers weist Dich dezent darauf hin, dass "gets" ein paar Fallstricke hat. Gets() ist sollte wenn moeglich vermieden werden, da Du keinerlei Bounds-Checking beim Einlesen der Strings machen kannst. D.h. Wenn der Nutzer einen String eingibt der die von dir vorgesehene Laenge ueberschreitet, wird auf nicht allokierten Speicher zugegriffen. Zitat aus der Man-Page:

BUGS

Never use gets(). Because it is impossible to tell with_

out knowing the data in advance how many characters gets()

will read, and because gets() will continue to store char_

acters past the end of the buffer, it is extremely danger_

ous to use. It has been used to break computer security.

Use fgets() instead.

It is not advisable to mix calls to input functions from

the stdio library with low - level calls to read() for the

file descriptor associated with the input stream; the

results will be undefined and very probably not what you

want.

Nic

Der Compiler will das Prog aber nicht ausführen... :(

Da es sich nur um eine Warnung des Linkers handelt und ich ansonsten keine Fehler (im Sinne von: der Compiler bricht ab) finden kann, solltest Du eigentlich eine Datei mit dem Namen "a.out" auf der Platte finden (Aufruf mit: "./a.out")

Nic

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.