Merge remote-tracking branch 'origin/main'

This commit is contained in:
Tamer Oeztuerk 2025-06-12 12:51:49 +02:00
commit a4e732ced9
3 changed files with 163 additions and 0 deletions

47
adrdruck.c Normal file
View File

@ -0,0 +1,47 @@
#include <stdio.h>
#include <string.h>
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);
}

28
adresse.txt Normal file
View File

@ -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
--------------------------------------------------

88
zahlsys.c Normal file
View File

@ -0,0 +1,88 @@
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
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 argc, char *argv[])
{
char eingabe[100] = {0};
for (int i = 1; i < argc; i++) {
strcat(eingabe, argv[i]);
if (i < argc - 1)
strcat(eingabe, " ");
}
char *pptr, *nptr;
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] == '-')
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;
case '-':
break;
default:
fehlerChar = pptr[i];
fehler = true;
break;
}
}
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);
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");
}
}