diff --git a/Makefile b/Makefile index 27041c7..c5f051a 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ SRCS = $(wildcard src/*.c) PROGS = $(patsubst src/%.c,%,$(SRCS)) -CFLAGS += -g -Wall -O0 -ansi -static +CFLAGS += -g -Wall -O0 -ansi VPATH = src/ all: $(PROGS) diff --git a/bin/1_n_a_factorial b/bin/1_n_a_factorial index 9fe91bb..eb1874f 100755 Binary files a/bin/1_n_a_factorial and b/bin/1_n_a_factorial differ diff --git a/bin/1_n_b_ascii b/bin/1_n_b_ascii index 7bd455f..59d2b26 100755 Binary files a/bin/1_n_b_ascii and b/bin/1_n_b_ascii differ diff --git a/bin/1_p_a_kanten b/bin/1_p_a_kanten index fb62352..6e8e3de 100755 Binary files a/bin/1_p_a_kanten and b/bin/1_p_a_kanten differ diff --git a/bin/1_v_a_square b/bin/1_v_a_square index f97d3ca..fb46c42 100755 Binary files a/bin/1_v_a_square and b/bin/1_v_a_square differ diff --git a/bin/2_p_b_raten b/bin/2_p_b_raten index a7a223a..afb2432 100755 Binary files a/bin/2_p_b_raten and b/bin/2_p_b_raten differ diff --git a/bin/2_p_c_tree b/bin/2_p_c_tree index 8f8d156..8848ea9 100755 Binary files a/bin/2_p_c_tree and b/bin/2_p_c_tree differ diff --git a/bin/2_p_d_einXeins b/bin/2_p_d_einXeins index 3d3cb0a..ff7b12b 100755 Binary files a/bin/2_p_d_einXeins and b/bin/2_p_d_einXeins differ diff --git a/bin/2_v_b_logic b/bin/2_v_b_logic index d5ef36d..a63434b 100755 Binary files a/bin/2_v_b_logic and b/bin/2_v_b_logic differ diff --git a/bin/3_n_a_xor_encryption b/bin/3_n_a_xor_encryption index ce9114b..071fe97 100755 Binary files a/bin/3_n_a_xor_encryption and b/bin/3_n_a_xor_encryption differ diff --git a/bin/3_n_b_scalarm b/bin/3_n_b_scalarm index 0cd595e..686ed3b 100755 Binary files a/bin/3_n_b_scalarm and b/bin/3_n_b_scalarm differ diff --git a/bin/3_n_c_userdb b/bin/3_n_c_userdb index 71a285e..edc219c 100755 Binary files a/bin/3_n_c_userdb and b/bin/3_n_c_userdb differ diff --git a/bin/3_p_a_zaehlen b/bin/3_p_a_zaehlen index 400ca21..5728014 100755 Binary files a/bin/3_p_a_zaehlen and b/bin/3_p_a_zaehlen differ diff --git a/bin/3_p_b_transponieren b/bin/3_p_b_transponieren index 145c170..e2efbc7 100755 Binary files a/bin/3_p_b_transponieren and b/bin/3_p_b_transponieren differ diff --git a/bin/3_p_c_parteien b/bin/3_p_c_parteien index 85bb260..f05abc8 100755 Binary files a/bin/3_p_c_parteien and b/bin/3_p_c_parteien differ diff --git a/bin/4_n_a_swap2 b/bin/4_n_a_swap2 new file mode 100755 index 0000000..363e80c Binary files /dev/null and b/bin/4_n_a_swap2 differ diff --git a/bin/4_n_b_strlen b/bin/4_n_b_strlen new file mode 100755 index 0000000..a051a34 Binary files /dev/null and b/bin/4_n_b_strlen differ diff --git a/bin/4_p_a_swap b/bin/4_p_a_swap new file mode 100755 index 0000000..dc83f6c Binary files /dev/null and b/bin/4_p_a_swap differ diff --git a/bin/4_p_c_strings b/bin/4_p_c_strings new file mode 100755 index 0000000..b1c59cc Binary files /dev/null and b/bin/4_p_c_strings differ diff --git a/src/4_n_a_swap2.c b/src/4_n_a_swap2.c new file mode 100644 index 0000000..e36d377 --- /dev/null +++ b/src/4_n_a_swap2.c @@ -0,0 +1,33 @@ +#include + +int i = 0; + +void swap (int * x, int * y) { + int temp; + temp = *x; + *x = *y; + *y = temp; +} + +int f() { + i++; + return i; +} + +int main () { + int feld[4] = {4, 3, 2, 1}; + int zahl1 = 5, zahl2 = 3; + + /* 2. Aufgabenteil */ + printf("vor swap: zahl1=%d, zahl2=%d\n", zahl1, zahl2); + swap(&zahl1, &zahl2); + printf("nach swap: zahl1=%d, zahl2=%d\n", zahl1, zahl2); + + /* 3. Aufgabenteil */ + printf ("feld-Inhalt vor swap: {%d, %d, %d, %d}\n", feld[0], feld[1], feld[2], feld[3]); + swap (&i, &feld[f()]); + printf ("feld-Inhalt nach swap: {%d, %d, %d, %d}\n", feld[0], feld[1], feld[2], feld[3]); + + return 0; +} + diff --git a/src/4_n_b_strlen.c b/src/4_n_b_strlen.c new file mode 100644 index 0000000..1f64c5f --- /dev/null +++ b/src/4_n_b_strlen.c @@ -0,0 +1,16 @@ +#include + +char *str = "Hello World!\n"; + +int main () { + int Laenge = 0; + char * str_pointer = str; + + while (*str_pointer++ != '\0' ) { + ++Laenge; + } + + printf("%d: %s", Laenge, str); + + return 0; +} diff --git a/src/4_p_a_swap.c b/src/4_p_a_swap.c new file mode 100644 index 0000000..5421374 --- /dev/null +++ b/src/4_p_a_swap.c @@ -0,0 +1,19 @@ +#include + +void swap(int * a, int * b); /* function declaration */ + +int main() { + int a = 4, b = 14; + + swap(&a, &b); + + printf("a = %d\nb = %d\n", a, b); + + return 0; +} + +void swap(int * a, int * b) { /* funtion implementation */ + int temp = *a; + *a = *b; + *b = temp; +} diff --git a/src/4_p_c_strings.c b/src/4_p_c_strings.c new file mode 100644 index 0000000..9eef9f7 --- /dev/null +++ b/src/4_p_c_strings.c @@ -0,0 +1,37 @@ +#include +#include + +#define MAX_LENGTH 81 /* 80 characters + '\0' termination */ + +int main () { + int i; + char str1[MAX_LENGTH]; /* Eingabestring */ + char str2[MAX_LENGTH]; /* Ausgabestring */ + char *p1, *p2; + + printf("Bitte ein Wort eingeben: "); + scanf(" %s", str1); + + /* soll nur eine Ausgabe erfolgen, geht dies auch ohne str2 und zwar wie folgt: */ + printf("So soll das Ergebnis aussehen: "); + + for (i = strlen(str1) - 1; i>=0; i--) { + printf("%c", str1[i]); + } + + /* nun mit Kopie in str2: */ + p1 = str1 + strlen(str1) -1; /* p1 zeigt auf das Ende von str1 */ + p2 = str2; /* p2 zeigt auf den Anfang von str2 */ + + /* von hinten nach vorn wird str1 zeichenweise nach str2 kopiert */ + while (p1 >= str1) { + *p2++ = *p1--; + } + *p2 = '\0'; /* str2 Sting-Endezeichen abschliessen */ + + /* Ausgabe beider Strings */ + printf("\n%s <--> %s\n", str1, str2); + + return 0; +} +