This commit is contained in:
2024-11-28 17:05:14 +01:00
parent b034aad83f
commit 19b5b201b0
205 changed files with 0 additions and 2340 deletions
@@ -1,21 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char * argv[]){
if (argc == 2) {
printf("bitte argument übergeben"); //argv ist programmname,
//argv[1] ist zhl daher 2 stk argc=2
}
else {
double zahl = atof(argv[1]); //covert to float
printf("%s³ = %f\n", argv[1], zahl*zahl*zahl);
}
return 0;
}
Binary file not shown.
@@ -1,37 +0,0 @@
/* point_1.c
*
* Datentyp eines zweidimensionalen Punktes
* verschiedene Methoden der Komponentenselektion
*/
#include <stdio.h>
struct point {
float x;
float y;
};
int main() {
struct point p1, p2;
struct point * ptr;
ptr = &p1;
// Pfeil- VS. Punktschreibweise
p1.x = 3; // Hier .x da p1 ein struct point ist
ptr->y = 4; // Hier ->y da ptr ein POINTER auf struct point ist
printf("\nx-Koordinate von p1: %f", ptr->x);
printf("\ny-Koordinate von p1: %f", (*ptr).y);
p2 = p1;
printf("\nx-Koordinate von p2: %f", p2.x);
printf("\ny-Koordinate von p2: %f", (&p2)->y);
printf("\n\n");
return 0;
}
Binary file not shown.
@@ -1,43 +0,0 @@
/* point_1.c
*
* Datentyp eines zweidimensionalen Punktes
* verschiedene Methoden der Komponentenselektion
*/
#include <stdio.h>
struct point {
float x;
float y;
};
void move(struct point * p, float newx, float newy){
p->x = newx;
p->y = newy;
}
int main() {
struct point p1, p2;
struct point * ptr;
ptr = &p1;
// Pfeil- VS. Punktschreibweise
p1.x = 3; // Hier .x da p1 ein struct point ist
ptr->y = 4; // Hier ->y da ptr ein POINTER auf struct point ist
printf("\nx-Koordinate von p1: %f", ptr->x);
printf("\ny-Koordinate von p1: %f", (*ptr).y);
p2 = p1;
move(ptr, -5, -3);
printf("\n Nach dem verschieben von p1:");
printf("\n x-Koordinate von p1 %f", p1.x);
printf("\ny-Koordinate von p1: %f", (&p1)->y);
printf("\nx-Koordinate von p2: %f", p2.x);
printf("\ny-Koordinate von p2: %f", (&p2)->y);
printf("\n\n");
return 0;
}
Binary file not shown.
@@ -1,47 +0,0 @@
/* point_3.c
*
* Datentyp eines zweidimensionalen Punktes
* mit Funktion zum Verschieben
* und dynamischer Speicherverwaltung
*/
#include <stdio.h>
#include <stdlib.h>
struct point {
float x;
float y;
};
void move(struct point * punkt, float dx, float dy) {
punkt->x += dx;
punkt->y += dy;
}
int main() {
struct point * ptr;
ptr = malloc(sizeof(struct point)); // impl. Typcast des Pointers
if (ptr != NULL) {
ptr->x = 10;
ptr->y = 20;
printf("\nx-Koordinate von p: %f", ptr->x);
printf("\ny-Koordinate von p: %f", ptr->y);
free(ptr);
printf("\n");
printf("\nnach free():");
// Dangling Pointer!
printf("\nx-Koordinate von p: %f", ptr->x);
printf("\ny-Koordinate von p: %f", ptr->y);
printf("\n\n");
}
return 0;
}
@@ -1,166 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
// Definition eines Punktes
typedef struct Point {
int x;
int y;
struct Point* next;
} Point;
// Funktion zum Erstellen eines neuen Punktes
Point* create_point(int x, int y) {
Point* new_point = (Point*)malloc(sizeof(Point));
if (new_point == NULL) {
printf("Memory allocation failed\n");
return NULL;
}
new_point->x = x;
new_point->y = y;
new_point->next = NULL;
return new_point;
}
// Funktion zum Anhängen eines Punktes an das Ende der Liste
void append(Point** head, int x, int y) {
Point* new_point = create_point(x, y);
if (*head == NULL) {
*head = new_point;
return;
}
Point* temp = *head;
while (temp->next != NULL) {
temp = temp->next;
}
temp->next = new_point;
}
// Funktion zum Entfernen des letzten Punktes aus der Liste
int shorten(Point** head) {
if (*head == NULL) {
return -1; // Liste ist leer
}
if ((*head)->next == NULL) {
free(*head);
*head = NULL;
return 0;
}
Point* temp = *head;
while (temp->next->next != NULL) {
temp = temp->next;
}
free(temp->next);
temp->next = NULL;
return 0;
}
// Funktion zum Ausgeben der Punkte in der Liste
void pretty_print(Point* head) {
Point* temp = head;
while (temp != NULL) {
printf("(%d, %d) -> ", temp->x, temp->y);
temp = temp->next;
}
printf("NULL\n");
}
// Funktion zum Einfügen eines Punktes an einer bestimmten Position
int insert(Point** head, int pos, int x, int y) {
if (pos < 0) {
return -1; // Ungültige Position
}
Point* new_point = create_point(x, y);
if (pos == 0) {
new_point->next = *head;
*head = new_point;
return 0;
}
Point* temp = *head;
for (int i = 0; i < pos - 1; i++) {
if (temp == NULL) {
free(new_point);
return -1; // Position außerhalb der Liste
}
temp = temp->next;
}
new_point->next = temp->next;
temp->next = new_point;
return 0;
}
// Funktion zum Spiegeln der Liste
int mirror(Point** head) {
if (*head == NULL || (*head)->next == NULL) {
return -1; // Leere Liste oder nur ein Element
}
Point* prev = NULL;
Point* current = *head;
Point* next = NULL;
while (current != NULL) {
next = current->next;
current->next = prev;
prev = current;
current = next;
}
*head = prev;
return 0;
}
// Hauptfunktion zum Testen der Implementierung
int main() {
Point* head = NULL;
// Testen der append-Funktion
append(&head, 1, 2);
append(&head, 3, 4);
pretty_print(head);
// Testen der shorten-Funktion
shorten(&head);
pretty_print(head);
shorten(&head);
pretty_print(head);
shorten(&head); // Sollte -1 zurückgeben, da die Liste leer ist
// Testen der insert-Funktion
insert(&head, 0, 5, 6);
insert(&head, 1, 7, 8);
pretty_print(head);
// Testen der mirror-Funktion
mirror(&head);
pretty_print(head);
return 0;
}
/*
punkt (x,y)
shorten(input: head, output: int (-1 nihctvgekalppt (bei leerer Liste, 0 hat geklappt)
free(speicherdresse von letztes element), vorletzten next auf null setzen,
next von next (übernächstes)
wenn liste nur noch ein element: head von nächstes auf null
insert: (input: head, pos, le), output: 0,-1(
-liste leer
-position außerhalb liste pos> len(head)
- erstes,
- insert: nur elemente an position einfügen, die zurzeit schin besetzsind
- nihct letzte Element+1 als position möglich keine verlängerung sondern nur zwischen vorhanden elementen! möglich muss zwischen elemente gepackt werden
-
mirror: input:head, ouput: int (-1(leere liste),0)
randfalle (ranfälle als komentar: wenn nru ein element, oer leer kein mirror möglich)
1. leere liste -> -1
2. 1 element -> -1
nxt pointer auf vorherigr le setzen
pretty print
*/
@@ -1,31 +0,0 @@
// typfehler.c
//
// Benutzereingaben mit Typfehler abfangen
#include <stdio.h>
#include <stdlib.h>
int main() {
float zahl;
int status;
char c;
while (1) {
printf("Geben Sie eine Zahl ein: ");
status = scanf("%f", &zahl);
if (status != 0){
break;
}
do {
//
c = getchar();
}
while (c != '\n');
printf(" Typfehler bei Benutzeingabe");
}
printf("Die Zahl ist %f\n", zahl);
return 0;
}