From dbe7ecfd43e29a5dbd617131d83580cf012e2c2d Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 5 Jun 2025 18:05:06 +0200 Subject: [PATCH 1/3] 26 --- zahlsys.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 zahlsys.c diff --git a/zahlsys.c b/zahlsys.c new file mode 100644 index 0000000..b468409 --- /dev/null +++ b/zahlsys.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include + +void ausgabeBinaer(int wert) { + for (int i = 31; i >= 0; i--) { + int bit = (wert >> i) & 1; + printf("%d", bit); + + if (i % 8 == 0 && i != 0) + printf(" "); + } + printf("\n"); +} + +int main() +{ + char eingabe[100] = {"--bo 127 --h"}; + + char *pptr, *nptr; + int wert; + bool b = false, o = false, h = false; + do{ + if(strchr(eingabe, ' ') == NULL) + break; + nptr = strchr(eingabe, ' ') + 1; + pptr = strtok(eingabe, " "); + if(pptr[0] == '-' && pptr[1]) + for (int i = 0; pptr[i]; ++i) { + switch (pptr[i]) { + case 'b': + b = true; + break; + case 'o': + o = true; + break; + case 'h': + h = true; + break; + } + } + else if(pptr[0] >= '0' && pptr[0] <= '9') + wert = atoi(pptr); + strcpy(eingabe, nptr); + } while (nptr != NULL); + + printf("Dezimal: %d\n", wert); + if(b){ + printf("Dual: "); + ausgabeBinaer(wert); + } + if(o) + printf("Oktal: %o\n", wert); + if(h) + printf("Hexadezimal: %x\n", wert); + if(b == 0 && o == 0 && h == 0){ + printf("Dual: "); + ausgabeBinaer(wert); + printf("Oktal: %o\n", wert); + printf("Hexadezimal: %x\n", wert); + } + +} \ No newline at end of file From 38fbd0d2a8791e9cee66ee2a028628f1da6e36c3 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 9 Jun 2025 15:19:02 +0200 Subject: [PATCH 2/3] 26 --- zahlsys.c | 80 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 28 deletions(-) diff --git a/zahlsys.c b/zahlsys.c index b468409..d93928a 100644 --- a/zahlsys.c +++ b/zahlsys.c @@ -7,26 +7,32 @@ void ausgabeBinaer(int wert) { for (int i = 31; i >= 0; i--) { int bit = (wert >> i) & 1; printf("%d", bit); - if (i % 8 == 0 && i != 0) printf(" "); } printf("\n"); } -int main() +int main(int argc, char *argv[]) { - char eingabe[100] = {"--bo 127 --h"}; + char eingabe[100] = {0}; + + for (int i = 1; i < argc; i++) { + strcat(eingabe, argv[i]); + if (i < argc - 1) + strcat(eingabe, " "); + } char *pptr, *nptr; - int wert; - bool b = false, o = false, h = false; - do{ - if(strchr(eingabe, ' ') == NULL) + char fehlerChar; + int wert, fehlerWert = 0; + bool b = false, o = false, h = false, fehler = false; + do { + if (!(strpbrk(eingabe, " -123456789"))) break; nptr = strchr(eingabe, ' ') + 1; pptr = strtok(eingabe, " "); - if(pptr[0] == '-' && pptr[1]) + if (pptr[0] == '-' && pptr[1] == '-') for (int i = 0; pptr[i]; ++i) { switch (pptr[i]) { case 'b': @@ -38,27 +44,45 @@ int main() case 'h': h = true; break; + case '-': + break; + default: + fehlerChar = pptr[i]; + fehler = true; + break; } } - else if(pptr[0] >= '0' && pptr[0] <= '9') - wert = atoi(pptr); - strcpy(eingabe, nptr); - } while (nptr != NULL); + else if ((pptr[0] >= '0' && pptr[0] <= '9') || (pptr[0] == '-' && pptr[1] != '-')) { + if (fehlerWert == 0) { + wert = atoi(pptr); + fehlerWert++; + } else + fehler = true; + } + if (nptr != NULL + 1) + strcpy(eingabe, nptr); + } while (nptr != NULL + 1); - printf("Dezimal: %d\n", wert); - if(b){ - printf("Dual: "); - ausgabeBinaer(wert); + if (fehler == false) { + printf("Dezimal: %d\n", wert); + if (b) { + printf("Dual: "); + ausgabeBinaer(wert); + } + if (o) + printf("Oktal: %o\n", wert); + if (h) + printf("Hexadezimal: %x\n", wert); + if (b == 0 && o == 0 && h == 0) { + printf("Dual: "); + ausgabeBinaer(wert); + printf("Oktal: %o\n", wert); + printf("Hexadezimal: %x\n", wert); + } + } else if (fehler == true) { + if (fehlerChar) + printf("...... Unerlaubte Option --%c\n", fehlerChar); + if (fehlerWert == 1) + printf("usage: zahlsys [--boh] zahl\n...... Es muss genau eine Zahl angegeben sein\n"); } - if(o) - printf("Oktal: %o\n", wert); - if(h) - printf("Hexadezimal: %x\n", wert); - if(b == 0 && o == 0 && h == 0){ - printf("Dual: "); - ausgabeBinaer(wert); - printf("Oktal: %o\n", wert); - printf("Hexadezimal: %x\n", wert); - } - -} \ No newline at end of file +} From 06683f9a7502cfd36675c7f05957e42c091f6c6a Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 10 Jun 2025 16:01:07 +0200 Subject: [PATCH 3/3] 30.1.3 --- adrdruck.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ adresse.txt | 28 ++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 adrdruck.c create mode 100644 adresse.txt diff --git a/adrdruck.c b/adrdruck.c new file mode 100644 index 0000000..f1ead56 --- /dev/null +++ b/adrdruck.c @@ -0,0 +1,47 @@ +#include +#include + +int main(){ + char name[50], vorname[50], strasse[50], hausnummer[50], plz[50], wohnort[50], telefon[50], fax[50]; + int n; + + char *filename = "adresse.txt", *ptr; + printf("Dieses Programm liest eine Adresse ein und schreibt\ndiese Adresse n mal in die Datei 'adresse.txt'\n"); + + printf("Vorname:"); + fgets(vorname, sizeof(vorname), stdin); + printf("Nachname:"); + fgets(name, sizeof(name), stdin); + printf("Strasse:"); + fgets(strasse, sizeof(strasse), stdin); + printf("Hausnummer:"); + fgets(hausnummer, sizeof(hausnummer), stdin); + printf("Postleitzahl:"); + fgets(plz, sizeof(plz), stdin); + printf("Wohnort:"); + fgets(wohnort, sizeof(wohnort), stdin); + printf("Telefon:"); + fgets(telefon, sizeof(plz), stdin); + printf("Fax:"); + fgets(fax, sizeof(fax), stdin); + + printf("Wie oft soll Adresse in Datei geschrieben werden:"); + scanf("%d", &n); + + ptr = strchr(strcat(vorname, name), '\n'); + ptr[0] = ' '; + ptr = strchr(strcat(strasse, hausnummer), '\n'); + ptr[0] = ' '; + ptr = strchr(strcat(plz, wohnort), '\n'); + ptr[0] = ' '; + + FILE *fp = fopen(filename, "w"); + + for (int i = 0; i < n; ++i) { + + fprintf(fp, "%s%s%s\nTel. %sFax %s", vorname, strasse, plz, telefon, fax); + fprintf(fp, "--------------------------------------------------\n"); + } + + fclose(fp); +} \ No newline at end of file diff --git a/adresse.txt b/adresse.txt new file mode 100644 index 0000000..35fd7c7 --- /dev/null +++ b/adresse.txt @@ -0,0 +1,28 @@ +Alexander Fleischmann +Bergenstrasse 172a +50636 Nordhofen + +Tel. 1233/213213 +Fax 9808/89798 +-------------------------------------------------- +Alexander Fleischmann +Bergenstrasse 172a +50636 Nordhofen + +Tel. 1233/213213 +Fax 9808/89798 +-------------------------------------------------- +Alexander Fleischmann +Bergenstrasse 172a +50636 Nordhofen + +Tel. 1233/213213 +Fax 9808/89798 +-------------------------------------------------- +Alexander Fleischmann +Bergenstrasse 172a +50636 Nordhofen + +Tel. 1233/213213 +Fax 9808/89798 +--------------------------------------------------