String Werte zuviel
-
Hey Jungs,
Ich habe einen String, der mit Binärzahlen belegt werden soll.
Mein Problem ist, dass der String immer mindestens 9 Zeichen angibt.
BSP:
wenn "001001" dastehen sollte, spuckt er: "001001 !!" aus. Das wirft natürlich alle anderen Funktionen des Programms durcheinander. Wie kann ich das verhindern?char M1[20];
binär(M1); // belegt M1 mit den Binärzahlenprintf("%s \n", M1); // gibt M1 aus
Danke euch schonmal
Drakus
-
Du könntest in der Funktion binär (kann man überhaupt ein 'ä' verwenden?) einfach ein Nullterminierungszeichen ('\0') hinter die letzte Ziffer der Binärzahl im string schreiben.
MfG, Jochen
-
Ah danke dir, hat super funktioniert...
(Im Programm hab ich Binär mit ae stehen ^^)Mit freundlichen Grüßen
Drakus
-
Jochen S. schrieb:
kann man überhaupt ein 'ä' verwenden?
Das kommt ganz darauf an, für welche Zahl das steht.
-
mngbd schrieb:
Jochen S. schrieb:
kann man überhaupt ein 'ä' verwenden?
Das kommt ganz darauf an, für welche Zahl das steht.
Er meinte im Bezeichner.
-
Nick Unbekannt schrieb:
Er meinte im Bezeichner.
Huh, klar eigentlich. Das würde ich lieber bleiben lassen. C99:
Both the basic source and basic execution character sets shall have the following members: the 26 uppercase letters of the Latin alphabet A B C D E F G H I J K L M N O P Q R S T U V W X Y Z the 26 lowercase letters of the Latin alphabet a b c d e f g h i j k l m n o p q r s t u v w x y z the 10 decimal digits 0 1 2 3 4 5 6 7 8 9 the following 29 graphic characters ! " # % & ' ( ) * + , - . / : ; < = > ? [ \ ] ^ _ { | } ~ the space character, and control characters representing horizontal tab, vertical tab, and form feed. ... If any other characters are encountered in a source file (except in an identifier, a character constant, a string literal, a header name, a comment, or a preprocessing token that is never converted to a token), the behavior is undefined.