34 lines
1.2 KiB
C
34 lines
1.2 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
// Funktionsprototypen (damit der Compiler weiß, dass es sie gibt)
|
|
void fehlerausgabe(const char *msg);
|
|
void dualzahl_einlesen(char *buffer, int maxlen);
|
|
void dualzahl_ausgeben(const char *buffer);
|
|
void dual_addiere_eins(const char *input, char *output, int maxlen);
|
|
|
|
#define MAXLEN 65 // Maximale Länge der Dualzahl (64 Bit + 1 für \0)
|
|
|
|
int main() {
|
|
char input[MAXLEN]; // Eingabepuffer für die Dualzahl
|
|
char output[MAXLEN]; // Ausgabepuffer für das Ergebnis
|
|
|
|
dualzahl_einlesen(input, MAXLEN); // Dualzahl vom Benutzer einlesen
|
|
|
|
// Prüfen, ob die Eingabe nur aus 0 und 1 besteht
|
|
for (int i = 0; input[i]; ++i) {
|
|
if (input[i] != '0' && input[i] != '1') {
|
|
fehlerausgabe("Nur 0 und 1 erlaubt!"); // Fehler ausgeben und beenden
|
|
}
|
|
}
|
|
|
|
dual_addiere_eins(input, output, MAXLEN); // 1 zur Dualzahl addieren
|
|
|
|
if (output[0] == '\0') { // Falls Fehler bei der Addition
|
|
fehlerausgabe("Fehler bei der Addition!");
|
|
}
|
|
|
|
dualzahl_ausgeben(output); // Ergebnis ausgeben
|
|
|
|
return 0; // Programm erfolgreich beenden
|
|
} |