upload stuff for 2nd tutorium, small code corrections, no longer reference wrong tutor on /sp website
This commit is contained in:
parent
9e94f7cbcc
commit
cb47190832
3 changed files with 69 additions and 8 deletions
|
|
@ -34,13 +34,10 @@ page_for: "sp1-lesson"
|
|||
- Mail an mich: <a href="mailto:nova.ruff@fau.de" class="link">nova.ruff@fau.de</a>
|
||||
- [SP-FAQ](https://sys.cs.fau.de/lehre/ss25/sp1/faq)
|
||||
|
||||
## Andere Tutoren
|
||||
## Andere Tutoren/Hilfreiche Links
|
||||
- [SP1 Website](https://sys.cs.fau.de/lehre/ss25/sp1)
|
||||
- [cdecl.org](https://cdecl.org/) um zu entziffern, was bei Pointern passiert
|
||||
- [Lukas (T03)](https://wwwcip.cs.fau.de/~uk16isyq/)
|
||||
- [Julian (T08)](https://jzbor.de/tut/sp1/)
|
||||
- [Stefan (T09)](https://wwwcip.cs.fau.de/~ok73ozus/sp)
|
||||
- [Luca (T11)](https://wwwcip.cs.fau.de/~am99ihig/sp)
|
||||
- [Philip (ehemalig)](https://wwwcip.cs.fau.de/~oj14ozun/sp1/)
|
||||
|
||||
## Hilfreiche Links
|
||||
- [cdecl.org](https://cdecl.org/) um zu entziffern, was bei Pointern passiert
|
||||
|
|
@ -106,7 +106,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
### Speicher für structs anlegen
|
||||
```c
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct listelement {
|
||||
int value;
|
||||
|
|
@ -121,6 +121,6 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
// ... rest vom program
|
||||
|
||||
free(element1)
|
||||
free(element1);
|
||||
}
|
||||
```
|
||||
64
src/sp1/ub2.md
Normal file
64
src/sp1/ub2.md
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
---
|
||||
title: "Übung 02 - Fehlerbehandlung, Soriteren"
|
||||
layout: "blog-post.njk"
|
||||
tags: "sp1-lesson"
|
||||
date: 2025-05-13
|
||||
---
|
||||
## Valgrind
|
||||
Um mit Valgrind das Program während der Laufzeit zu analysieren, muss beim kompilieren das Program mit dem `-g` flag übersetzt worden sein.
|
||||
So kann Valgrind ausgeführt werden (mit den empfohlenen Flags aus der Übung):
|
||||
```bash
|
||||
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./lilo
|
||||
```
|
||||
weitere nützliche flags:
|
||||
- `--track-fds=yes`: Alle noch offenen file pointer bei beendigung des Programms ausgeben
|
||||
|
||||
## Beispiel Programme aus der Präsenzübung
|
||||
### 20 Zufällig generierte Integers mit qsort() sortieren
|
||||
```c
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#define COUNT 20
|
||||
|
||||
static int compare(const void *a, const void *b) {
|
||||
// wir wissen, dass pointers zu integers gepasst werden (wir sortieren ints)
|
||||
const int *ia = (const int *)a;
|
||||
const int *ib = (const int *)b;
|
||||
|
||||
if (*ia < *ib) {
|
||||
return -1;
|
||||
} else if (*ia == *ib) {
|
||||
return 0;
|
||||
} else {
|
||||
return +1;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
srand(time(NULL));
|
||||
|
||||
// Speicher für die Zahlen anlegen
|
||||
int *nums = malloc(sizeof(int) * COUNT);
|
||||
if (nums == NULL) {
|
||||
perror("malloc");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Zufallszahlen generieren
|
||||
for (int i = 0; i < COUNT; i++) {
|
||||
int r = rand();
|
||||
nums[i] = r;
|
||||
}
|
||||
|
||||
qsort(nums, COUNT, sizeof(int), compare);
|
||||
|
||||
// die zahlen sortiert auf stdout ausgeben
|
||||
for (int i = 0; i < COUNT; i++) {
|
||||
printf("%d\n", nums[i]);
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS)
|
||||
}
|
||||
```
|
||||
Loading…
Add table
Reference in a new issue