> ## Documentation Index
> Fetch the complete documentation index at: https://docs.baenninger.me/llms.txt
> Use this file to discover all available pages before exploring further.

# Input und Output

## Output﻿

Um in C etwas in die Konsole auszugeben, benutzt man hauptsächlich die `printf()`-Funktion.

```c theme={null}
printf("Hallo Welt"); // Hallo Welt
```

### Variablen ausgeben﻿

Um Variablen auszugeben, benutzt man das Formatzeichen des Typs an der Stelle, wo man die Variable haben möchte.

```c theme={null}
int num = 5;
printf("Number = %d", num); // Number = 5
```

## Input﻿

### `scanf()`﻿

Um User-Input einzulesen, kann man die Funktion `scanf()` benutzen.

```c theme={null}
int num;

printf("Enter an integer: ");
scanf("%d", &num);
printf("Number = %d", num);
```

Man kann auch mehrere Argumente gleichzeitig entgegennehmen.

```c theme={null}
int a;
float b;

printf("First enter integer and than a float: ");
scanf("%d %f", &a, &b);

printf("You entered %d and %f", a, b);
```

Zudem sollte nach jedem `scanf()` der Cache des `stdin` geleert werden. Das kann mit der Funktion `fflush(stdin)` machen.

### `fgets()`﻿

Wenn man Strings mit `scanf()` einlesen will, wird nur alles bis zum ersten Leerschlag eingelesen. Um dieses Problem zu beheben, gibt es eine andere Funktion:

```c theme={null}
char input[100];

printf("Type full name: ");
fgets(input, 100, stdin);
printf("Input is: %s", input);
```

Die `100` ist dabei durch die Grösse des Strings zu ersetzen.
