Compare commits
11
Commits
aace8845a8
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5572368006 | ||
|
|
8705b7b629 | ||
|
|
3168349326 | ||
|
|
da74a8a87e | ||
|
|
437d5a9b2e | ||
|
|
8b4a7b9150 | ||
|
|
5024214330 | ||
|
|
a34f461661 | ||
|
|
122dcd5a02 | ||
|
|
aafbd8a4e0 | ||
|
|
5bed228605 |
No files matched your search
+115
@@ -0,0 +1,115 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#define SIZE_EINGABE 11
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int tag;
|
||||||
|
int monat;
|
||||||
|
int jahr;
|
||||||
|
} Datum;
|
||||||
|
|
||||||
|
|
||||||
|
int datum_einlesen(Datum *datum, int i) {
|
||||||
|
char eingabe[SIZE_EINGABE] = {0};
|
||||||
|
printf("%d. Datum (tt.mm.jjjj): ", i);
|
||||||
|
|
||||||
|
if (fgets(eingabe, SIZE_EINGABE, stdin) != NULL) {
|
||||||
|
|
||||||
|
int laenge = strlen(eingabe);
|
||||||
|
if (eingabe[laenge - 1] == '\n') {
|
||||||
|
eingabe[laenge - 1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sscanf(eingabe, "%d.%d.%d", &datum->tag, &datum->monat, &datum->jahr) == 3) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int schaltjahr_berechnen(int jahr) {
|
||||||
|
return (jahr % 4 == 0 && (jahr % 100 != 0 || jahr % 400 == 0)) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int alle_tage_bis_datum_berechnen(Datum *datum) {
|
||||||
|
int aktuelles_datum_tage = 0;
|
||||||
|
const int monate_kein_schaltjahr[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||||
|
const int monate_schaltjahr[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||||
|
|
||||||
|
|
||||||
|
for(int i = 0; i < datum->jahr; i++){
|
||||||
|
int schaltjahr = schaltjahr_berechnen(i);
|
||||||
|
if(schaltjahr == 1) {
|
||||||
|
aktuelles_datum_tage += 366;
|
||||||
|
}
|
||||||
|
else if(schaltjahr == 0) {
|
||||||
|
aktuelles_datum_tage += 365;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(int j = 0; j < (datum->monat) - 1 ; j++) {
|
||||||
|
int schaltjahr = schaltjahr_berechnen(datum->jahr);
|
||||||
|
if(schaltjahr == 1) {
|
||||||
|
aktuelles_datum_tage += monate_schaltjahr[j];
|
||||||
|
}
|
||||||
|
else if(schaltjahr == 0) {
|
||||||
|
aktuelles_datum_tage += monate_kein_schaltjahr[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(int k = 0; k < datum->tag; k++) {
|
||||||
|
aktuelles_datum_tage++;
|
||||||
|
}
|
||||||
|
return aktuelles_datum_tage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int tage_diff(Datum *datum_1, Datum *datum_2) {
|
||||||
|
|
||||||
|
int tage_diff_gesamt = 0;
|
||||||
|
|
||||||
|
int tage_datum_1 = alle_tage_bis_datum_berechnen(datum_1);
|
||||||
|
int tage_datum_2 = alle_tage_bis_datum_berechnen(datum_2);
|
||||||
|
|
||||||
|
tage_diff_gesamt = abs(tage_datum_1 - tage_datum_2);
|
||||||
|
|
||||||
|
return tage_diff_gesamt;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Datum datum_1, datum_2;
|
||||||
|
|
||||||
|
|
||||||
|
if (!datum_einlesen(&datum_1, 1)) {
|
||||||
|
printf("Fehler beim Einlesen von Datum 1.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
fflush(stdin);
|
||||||
|
|
||||||
|
if (!datum_einlesen(&datum_2, 2)) {
|
||||||
|
printf("Fehler beim Einlesen von Datum 2.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int tage_diff_aus = tage_diff(&datum_1, &datum_2); {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("..... Differenz: %d Tage .....", tage_diff_aus);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Created by Lennart Pecher on 16.05.25.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Created by Lennart Pecher on 16.05.25.
|
||||||
|
//
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define SIZE 3
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
const char *mischungen[SIZE][SIZE] = {
|
||||||
|
{"Gelb", "Rot", "Purpur"},
|
||||||
|
{"Blau", "Purpur", "Violett"}
|
||||||
|
};
|
||||||
|
|
||||||
|
char eingabe1[20], eingabe2[20];
|
||||||
|
int index1 = -1, index2 = -1;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
scanf("%s", eingabe1);
|
||||||
|
|
||||||
|
for (int i = 0; i < SIZE; i++) {
|
||||||
|
if (strcasecmp(eingabe1, farben[i]) == 0) {
|
||||||
|
index1 = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index1 != -1) break;
|
||||||
|
else printf("... unbekannte Grundfarbe '%s'. Bitte erneut eingeben.\n", eingabe1);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
scanf("%s", eingabe2);
|
||||||
|
|
||||||
|
for (int i = 0; i < SIZE; i++) {
|
||||||
|
if (strcasecmp(eingabe2, farben[i]) == 0) {
|
||||||
|
index2 = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index2 != -1) break;
|
||||||
|
else printf("... unbekannte Grundfarbe '%s'. Bitte erneut eingeben.\n", eingabe2);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *ergebnis = mischungen[index1][index2];
|
||||||
|
printf("Die Mischung aus %s und %s ergibt: %s\n", farben[index1], farben[index2], ergebnis);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
+92
@@ -0,0 +1,92 @@
|
|||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define MAX 100
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
long vorkomma;
|
||||||
|
long nachkomma;
|
||||||
|
int nachkomma_stellen;
|
||||||
|
} Kommazahl;
|
||||||
|
|
||||||
|
// Funktion zum Potenzieren (10^n)
|
||||||
|
long potenz(int basis, int exponent) {
|
||||||
|
long result = 1;
|
||||||
|
for (int i = 0; i < exponent; i++) {
|
||||||
|
result *= basis;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Funktion zum Aufteilen der Zahl in Vor- und Nachkommateil
|
||||||
|
Kommazahl parseKommazahl(char *eingabe) {
|
||||||
|
Kommazahl z = {0, 0, 0};
|
||||||
|
char *komma = strchr(eingabe, ','); //Überprüfung ob Zahl ein Komma besitzt
|
||||||
|
|
||||||
|
if (komma) {
|
||||||
|
*komma = '\0'; // 0 ersetzt Komma
|
||||||
|
z.vorkomma = atol(eingabe); // Wandelt Vorkomma in Ganzzahl um
|
||||||
|
char *nachkomma_str = komma + 1;
|
||||||
|
z.nachkomma = atol(nachkomma_str); // Wandelt nachkomma in Ganzzahl um
|
||||||
|
z.nachkomma_stellen = strlen(nachkomma_str);
|
||||||
|
} else {
|
||||||
|
z.vorkomma = atol(eingabe);
|
||||||
|
z.nachkomma = 0;
|
||||||
|
z.nachkomma_stellen = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Kommazahl eingaben[MAX];
|
||||||
|
int anzahl = 0;
|
||||||
|
int max_nachkomma_stellen = 0;
|
||||||
|
|
||||||
|
printf("Gib Deine Kommazahlen ein (Abschluss mit Leerzeile)\n");
|
||||||
|
|
||||||
|
char zeile[100];
|
||||||
|
while (fgets(zeile, sizeof(zeile), stdin)) {
|
||||||
|
// Entferne Zeilenumbruch
|
||||||
|
size_t len = strlen(zeile);
|
||||||
|
if (len > 0 && zeile[len - 1] == '\n') zeile[len - 1] = '\0';
|
||||||
|
if (strlen(zeile) == 0) break;
|
||||||
|
|
||||||
|
// Entferne Leerzeichen
|
||||||
|
for (int i = 0; zeile[i]; i++) {
|
||||||
|
if (zeile[i] == ' ') {
|
||||||
|
memmove(&zeile[i], &zeile[i + 1], strlen(&zeile[i]));
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Kommazahl k = parseKommazahl(zeile);
|
||||||
|
eingaben[anzahl] = k;
|
||||||
|
if (k.nachkomma_stellen > max_nachkomma_stellen)
|
||||||
|
max_nachkomma_stellen = k.nachkomma_stellen;
|
||||||
|
anzahl++;
|
||||||
|
}
|
||||||
|
|
||||||
|
Kommazahl summe = {0, 0, max_nachkomma_stellen};
|
||||||
|
|
||||||
|
for (int i = 0; i < anzahl; i++) {
|
||||||
|
Kommazahl z = eingaben[i];
|
||||||
|
summe.vorkomma += z.vorkomma;
|
||||||
|
|
||||||
|
int faktor = potenz(10, max_nachkomma_stellen - z.nachkomma_stellen);
|
||||||
|
summe.nachkomma += z.nachkomma * faktor;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Übertrag
|
||||||
|
long übertrag = summe.nachkomma / potenz(10, max_nachkomma_stellen);
|
||||||
|
summe.vorkomma += übertrag;
|
||||||
|
summe.nachkomma = summe.nachkomma % potenz(10, max_nachkomma_stellen);
|
||||||
|
|
||||||
|
printf("= %ld,%0*ld\n", summe.vorkomma, max_nachkomma_stellen, summe.nachkomma);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define MAX 100
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
long vorkomma;
|
||||||
|
long nachkomma;
|
||||||
|
int nachkomma_stellen;
|
||||||
|
} Kommazahl;
|
||||||
|
|
||||||
|
// Funktion zum Potenzieren (10^n)
|
||||||
|
long potenz(int basis, int exponent) {
|
||||||
|
long result = 1;
|
||||||
|
for (int i = 0; i < exponent; i++) {
|
||||||
|
result *= basis;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Funktion zum Aufteilen der Zahl in Vor- und Nachkommateil
|
||||||
|
Kommazahl parseKommazahl(char *eingabe) {
|
||||||
|
Kommazahl z = {0, 0, 0};
|
||||||
|
char *komma = strchr(eingabe, ','); //Überprüfung ob Zahl ein Komma besitzt
|
||||||
|
|
||||||
|
if (komma) {
|
||||||
|
*komma = '\0'; // 0 ersetzt Komma
|
||||||
|
z.vorkomma = atol(eingabe); // Wandelt Vorkomma in Ganzzahl um
|
||||||
|
char *nachkomma_str = komma + 1;
|
||||||
|
z.nachkomma = atol(nachkomma_str); // Wandelt nachkomma in Ganzzahl um
|
||||||
|
z.nachkomma_stellen = strlen(nachkomma_str);
|
||||||
|
} else {
|
||||||
|
z.vorkomma = atol(eingabe);
|
||||||
|
z.nachkomma = 0;
|
||||||
|
z.nachkomma_stellen = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Kommazahl eingaben[MAX];
|
||||||
|
int anzahl = 0;
|
||||||
|
int max_nachkomma_stellen = 0;
|
||||||
|
|
||||||
|
printf("Gib Deine Kommazahlen ein (Abschluss mit Leerzeile)\n");
|
||||||
|
|
||||||
|
char zeile[100];
|
||||||
|
while (fgets(zeile, sizeof(zeile), stdin)) {
|
||||||
|
// Entferne Zeilenumbruch
|
||||||
|
size_t len = strlen(zeile);
|
||||||
|
if (len > 0 && zeile[len - 1] == '\n') zeile[len - 1] = '\0';
|
||||||
|
if (strlen(zeile) == 0) break;
|
||||||
|
|
||||||
|
// Entferne Leerzeichen
|
||||||
|
for (int i = 0; zeile[i]; i++) {
|
||||||
|
if (zeile[i] == ' ') {
|
||||||
|
memmove(&zeile[i], &zeile[i + 1], strlen(&zeile[i]));
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Kommazahl k = parseKommazahl(zeile);
|
||||||
|
eingaben[anzahl] = k;
|
||||||
|
if (k.nachkomma_stellen > max_nachkomma_stellen)
|
||||||
|
max_nachkomma_stellen = k.nachkomma_stellen;
|
||||||
|
anzahl++;
|
||||||
|
}
|
||||||
|
|
||||||
|
Kommazahl summe = {0, 0, max_nachkomma_stellen};
|
||||||
|
|
||||||
|
for (int i = 0; i < anzahl; i++) {
|
||||||
|
Kommazahl z = eingaben[i];
|
||||||
|
summe.vorkomma += z.vorkomma;
|
||||||
|
|
||||||
|
int faktor = potenz(10, max_nachkomma_stellen - z.nachkomma_stellen);
|
||||||
|
summe.nachkomma += z.nachkomma * faktor;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Übertrag
|
||||||
|
long übertrag = summe.nachkomma / potenz(10, max_nachkomma_stellen);
|
||||||
|
summe.vorkomma += übertrag;
|
||||||
|
summe.nachkomma = summe.nachkomma % potenz(10, max_nachkomma_stellen);
|
||||||
|
|
||||||
|
printf("= %ld,%0*ld\n", summe.vorkomma, max_nachkomma_stellen, summe.nachkomma);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
+62
@@ -0,0 +1,62 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
NATRONLAUGE,
|
||||||
|
KALILAUGE,
|
||||||
|
KALKWASSER,
|
||||||
|
ANZAHL_LAUGEN
|
||||||
|
} Lauge;
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SALZSAEURE,
|
||||||
|
SCHWEFELSAEURE,
|
||||||
|
SALPETERSAEURE,
|
||||||
|
KOHLENSAEURE,
|
||||||
|
ANZAHL_SAEUREN
|
||||||
|
} Saeure;
|
||||||
|
|
||||||
|
|
||||||
|
const char* mischtabelle[ANZAHL_LAUGEN][ANZAHL_SAEUREN] = {
|
||||||
|
{"Natriumchlorid", "Natriumsulfat", "Natriumnitrat", "Natriumcarbonat"},
|
||||||
|
{"Kaliumchlorid", "Kaliumsulfat", "Kaliumnitrat", "Kaliumcarbonat"},
|
||||||
|
{"Calciumchlorid", "Calciumsulfat", "Calciumnitrat", "Calciumcarbonat"}
|
||||||
|
};
|
||||||
|
|
||||||
|
const char* laugen_namen[ANZAHL_LAUGEN] = {
|
||||||
|
"Natronlauge",
|
||||||
|
"Kalilauge",
|
||||||
|
"Kalkwasser"
|
||||||
|
};
|
||||||
|
|
||||||
|
const char* saeure_namen[ANZAHL_SAEUREN] = {
|
||||||
|
"Salzsäure",
|
||||||
|
"Schwefelsäure",
|
||||||
|
"Salpetersäure",
|
||||||
|
"Kohlensäure"
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
printf(" ||");
|
||||||
|
for (int s = 0; s < ANZAHL_SAEUREN; s++) {
|
||||||
|
printf(" %-14s|", saeure_namen[s]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
printf("-----------++");
|
||||||
|
for (int s = 0; s < ANZAHL_SAEUREN; s++) {
|
||||||
|
printf("---------------|");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
|
||||||
|
for (int l = 0; l < ANZAHL_LAUGEN; l++) {
|
||||||
|
printf("%-11s||", laugen_namen[l]);
|
||||||
|
for (int s = 0; s < ANZAHL_SAEUREN; s++) {
|
||||||
|
printf(" %-14s|", mischtabelle[l][s]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
+141
@@ -0,0 +1,141 @@
|
|||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#define SIZE_NAME 100
|
||||||
|
|
||||||
|
typedef struct knotenNamensliste {
|
||||||
|
char name[SIZE_NAME];
|
||||||
|
struct knotenNamensliste* next;
|
||||||
|
struct knotenNamensliste* prev;
|
||||||
|
} knotenNamensliste_t;
|
||||||
|
|
||||||
|
knotenNamensliste_t* neuenKnotenErstellen(char *aktuellerName) {
|
||||||
|
knotenNamensliste_t *neuerKnoten = (knotenNamensliste_t*)malloc(sizeof(knotenNamensliste_t));
|
||||||
|
if (neuerKnoten == NULL) {
|
||||||
|
printf("Speicher konnte nicht zugewiesen werden!\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
strncpy(neuerKnoten->name, aktuellerName, SIZE_NAME - 1);
|
||||||
|
neuerKnoten->prev = NULL;
|
||||||
|
neuerKnoten->next = NULL;
|
||||||
|
|
||||||
|
return neuerKnoten;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int namenEinlesen(char *aktuellerName) {
|
||||||
|
printf("Name (Leere Eingabe zum Beenden):\t");
|
||||||
|
if (fgets(aktuellerName, SIZE_NAME, stdin) != NULL) {
|
||||||
|
int laenge = strlen(aktuellerName);
|
||||||
|
if (aktuellerName[laenge-1] == '\n') {
|
||||||
|
aktuellerName[laenge-1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen(aktuellerName) == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int wahlListe() {
|
||||||
|
int wahl;
|
||||||
|
printf("Welche Liste (1 oder 2):\t");
|
||||||
|
scanf("%d", &wahl);
|
||||||
|
while (getchar() != '\n');
|
||||||
|
return wahl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void listeSortieren(knotenNamensliste_t **listeHead, char *aktuellerName) {
|
||||||
|
|
||||||
|
knotenNamensliste_t *neuerKnoten = neuenKnotenErstellen(aktuellerName);
|
||||||
|
|
||||||
|
knotenNamensliste_t *temp = *listeHead;
|
||||||
|
|
||||||
|
//Überprüfung ob Name bereits vorhanden
|
||||||
|
while (temp != NULL) {
|
||||||
|
if (strcmp(temp->name, aktuellerName) == 0) {
|
||||||
|
free(neuerKnoten);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (*listeHead == NULL) {
|
||||||
|
*listeHead = neuerKnoten;
|
||||||
|
} else {
|
||||||
|
temp = *listeHead;
|
||||||
|
|
||||||
|
//Alphabetische Sortierung
|
||||||
|
while (temp->next != NULL && strcmp(temp->name, aktuellerName) < 0) {
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (strcmp(temp->name, aktuellerName) > 0) {
|
||||||
|
|
||||||
|
neuerKnoten->next = temp;
|
||||||
|
neuerKnoten->prev = temp->prev;
|
||||||
|
if (temp->prev != NULL) {
|
||||||
|
temp->prev->next = neuerKnoten;
|
||||||
|
} else {
|
||||||
|
*listeHead = neuerKnoten;
|
||||||
|
}
|
||||||
|
temp->prev = neuerKnoten;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
temp->next = neuerKnoten;
|
||||||
|
neuerKnoten->prev = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void ausgabeListe(knotenNamensliste_t *listeHead) {
|
||||||
|
knotenNamensliste_t *temp = listeHead;
|
||||||
|
while (temp != NULL) {
|
||||||
|
printf("Name: %s\n", temp->name);
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
knotenNamensliste_t *listeGemischtHead = NULL;
|
||||||
|
knotenNamensliste_t *listeEinsHead = NULL;
|
||||||
|
knotenNamensliste_t *listeZweiHead = NULL;
|
||||||
|
char aktuellerName[SIZE_NAME];
|
||||||
|
|
||||||
|
while (namenEinlesen(aktuellerName) == 1) {
|
||||||
|
int listeZuweisen = wahlListe();
|
||||||
|
if (listeZuweisen == 1) {
|
||||||
|
listeSortieren(&listeEinsHead, aktuellerName);
|
||||||
|
} else if (listeZuweisen == 2) {
|
||||||
|
listeSortieren(&listeZweiHead, aktuellerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
listeSortieren(&listeGemischtHead, aktuellerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Liste 1:\n");
|
||||||
|
ausgabeListe(listeEinsHead);
|
||||||
|
printf("Liste 2:\n");
|
||||||
|
ausgabeListe(listeZweiHead);
|
||||||
|
printf("Liste gemischt:\n");
|
||||||
|
ausgabeListe(listeGemischtHead);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Created by Lennart Pecher on 23.05.25.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Created by Lennart Pecher on 23.05.25.
|
||||||
|
//
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
int eingabe() {
|
||||||
|
int x;
|
||||||
|
scanf("%d", &x);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int input = 1;
|
||||||
|
bool *primzahlen;
|
||||||
|
|
||||||
|
while (input != 0) {
|
||||||
|
printf("Bis wohin sollen die Primzahlen berechnet werden (Ende=0) ? ");
|
||||||
|
input = eingabe();
|
||||||
|
|
||||||
|
if(input == 0){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
primzahlen = (bool *) malloc(input * sizeof(bool));
|
||||||
|
|
||||||
|
for (int i = 2; i * i <= input; i++) {
|
||||||
|
if (primzahlen[i] == true) {
|
||||||
|
for (int j = i * i; j <= input; j += i) {
|
||||||
|
primzahlen[j] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 2; i <= input; i++) {
|
||||||
|
if (primzahlen[i] == true) {
|
||||||
|
printf("%d ", i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
free(primzahlen);
|
||||||
|
}
|
||||||
|
printf("Programm beendet");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
+13
-26
@@ -13,55 +13,52 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#define MAX_LENGTH 101
|
#define MAX_LENGTH 1001
|
||||||
#define MAX_WORD_LENGTH 11
|
#define MAX_WORD_LENGTH 101
|
||||||
#define MAX_EXCHANGE_WORD_LENGTH 21
|
#define MAX_EXCHANGE_WORD_LENGTH 201
|
||||||
#define MAX_POSITION 10
|
#define MAX_POSITION 100
|
||||||
|
|
||||||
void get_input_string(char * input ) {
|
void get_input_string(char * input ) {
|
||||||
printf("Geben Sie einen Text mit maximal %d Zeichen ein: ", MAX_LENGTH-1);
|
printf("Geben Sie einen Text mit maximal %d Zeichen ein: ", MAX_LENGTH-1);
|
||||||
scanf("%100[^\n]", input);
|
scanf("%1000[^\n]", input);
|
||||||
while (getchar() != '\n');
|
while (getchar() != '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_word_to_replace(char*get_word) {
|
void get_word_to_replace(char*get_word) {
|
||||||
printf("Welches Wort soll ersetzt werden? (Maximale Wortlänge: %d): ", MAX_WORD_LENGTH-1);
|
printf("Welches Wort soll ersetzt werden? (Maximale Wortlänge: %d): ", MAX_WORD_LENGTH-1);
|
||||||
scanf("%10[^\n]", get_word);
|
scanf("%100[^\n]", get_word);
|
||||||
while (getchar() != '\n');
|
while (getchar() != '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_new_word(char*new_word) {
|
void get_new_word(char*new_word) {
|
||||||
printf("Durch welches Wort soll dieses ersetzt werden? (Maximale Wortlänge des neuen Wortes: %d): ", MAX_EXCHANGE_WORD_LENGTH-1);
|
printf("Durch welches Wort soll dieses ersetzt werden? (Maximale Wortlänge des neuen Wortes: %d): ", MAX_EXCHANGE_WORD_LENGTH-1);
|
||||||
scanf("%20[^\n]", new_word);
|
scanf("%200[^\n]", new_word);
|
||||||
while (getchar() != '\n');
|
while (getchar() != '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
int find_word_positions(const char *input_sentence, const char *target_word, int position_target_word[]) {
|
int find_word_positions(const char *input_sentence, const char *target_word, int position_target_word[]) {
|
||||||
|
|
||||||
int counter_word_found = 0;
|
int counter_word_found = 0;
|
||||||
|
|
||||||
char *sentence_ptr = (char*)input_sentence;
|
char *sentence_ptr = (char*)input_sentence;
|
||||||
|
|
||||||
if(strstr(sentence_ptr, target_word) == NULL) {
|
if(strstr(sentence_ptr, target_word) == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
do{
|
|
||||||
char *ptr_position_target_word = strstr(sentence_ptr, target_word);
|
|
||||||
|
|
||||||
|
do {
|
||||||
|
char *ptr_position_target_word = strstr(sentence_ptr, target_word);
|
||||||
int position_before_target_word = ptr_position_target_word - input_sentence - 1;
|
int position_before_target_word = ptr_position_target_word - input_sentence - 1;
|
||||||
|
|
||||||
int position_after_target_word = ptr_position_target_word - input_sentence + strlen(target_word);
|
int position_after_target_word = ptr_position_target_word - input_sentence + strlen(target_word);
|
||||||
|
|
||||||
if (isalpha(input_sentence[position_before_target_word]) || isalpha(input_sentence[position_after_target_word])) {
|
if (isalpha(input_sentence[position_before_target_word]) || isalpha(input_sentence[position_after_target_word])) {
|
||||||
sentence_ptr = ptr_position_target_word + strlen(target_word);
|
sentence_ptr = ptr_position_target_word + strlen(target_word);
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
position_target_word[counter_word_found] = ptr_position_target_word - input_sentence;
|
position_target_word[counter_word_found] = ptr_position_target_word - input_sentence;
|
||||||
|
|
||||||
sentence_ptr = ptr_position_target_word + strlen(target_word);
|
sentence_ptr = ptr_position_target_word + strlen(target_word);
|
||||||
|
|
||||||
counter_word_found++;
|
counter_word_found++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}while(strstr(sentence_ptr, target_word) != NULL);
|
}while(strstr(sentence_ptr, target_word) != NULL);
|
||||||
|
|
||||||
return counter_word_found;
|
return counter_word_found;
|
||||||
@@ -74,15 +71,12 @@ void replace_word_in_sentence(char *input_sentence, const char *replacement_word
|
|||||||
int last_position = 0;
|
int last_position = 0;
|
||||||
|
|
||||||
for (int i = 0; i < counter_word_found; i++) {
|
for (int i = 0; i < counter_word_found; i++) {
|
||||||
|
|
||||||
strncat(updated_sentence, input_sentence + last_position, positions_target_word[i] - last_position);
|
strncat(updated_sentence, input_sentence + last_position, positions_target_word[i] - last_position);
|
||||||
|
|
||||||
strncat(updated_sentence, replacement_word, MAX_EXCHANGE_WORD_LENGTH - 1);
|
strncat(updated_sentence, replacement_word, MAX_EXCHANGE_WORD_LENGTH - 1);
|
||||||
|
|
||||||
last_position = positions_target_word[i] + strlen(target_word);
|
last_position = positions_target_word[i] + strlen(target_word);
|
||||||
}
|
}
|
||||||
strncat(updated_sentence, input_sentence + last_position, MAX_LENGTH - strlen(updated_sentence) - 1);
|
|
||||||
|
|
||||||
|
strncat(updated_sentence, input_sentence + last_position, MAX_LENGTH - strlen(updated_sentence) - 1);
|
||||||
strncpy(input_sentence, updated_sentence, MAX_LENGTH - 1);
|
strncpy(input_sentence, updated_sentence, MAX_LENGTH - 1);
|
||||||
input_sentence[MAX_LENGTH] = '\0';
|
input_sentence[MAX_LENGTH] = '\0';
|
||||||
}
|
}
|
||||||
@@ -100,9 +94,7 @@ int main(void) {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
get_word_to_replace(target_word);
|
get_word_to_replace(target_word);
|
||||||
|
|
||||||
get_new_word(replacement_word);
|
get_new_word(replacement_word);
|
||||||
|
|
||||||
word_found = find_word_positions(input_sentence, target_word, positions_target_word);
|
word_found = find_word_positions(input_sentence, target_word, positions_target_word);
|
||||||
|
|
||||||
if (word_found == 0) {
|
if (word_found == 0) {
|
||||||
@@ -111,7 +103,7 @@ int main(void) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
replace_word_in_sentence(input_sentence, replacement_word, target_word, positions_target_word, word_found);
|
replace_word_in_sentence(input_sentence, replacement_word, target_word, positions_target_word, word_found);
|
||||||
printf("\n....: %s\n", input_sentence);
|
printf("\n....Neuer String: %s\n", input_sentence);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Noch eine Einsetzung (j/n)? ");
|
printf("Noch eine Einsetzung (j/n)? ");
|
||||||
@@ -128,8 +120,3 @@ int main(void) {
|
|||||||
// Created by Lennart Pecher on 25.04.25.
|
// Created by Lennart Pecher on 25.04.25.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// Created by Lennart Pecher on 25.04.25.
|
|
||||||
//
|
|
||||||
Reference in new issue
Block a user