Last active
June 5, 2018 14:35
-
-
Save d630/06ff000c361a72c4c73771a2f63df055 to your computer and use it in GitHub Desktop.
test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #define MAX 66 | |
| struct Personal { | |
| char Vorname[MAX]; | |
| char Nachname[MAX]; | |
| int Alter; | |
| double Gehalt; | |
| }; | |
| int countLetter(char *str, char c) | |
| { | |
| int n = 0; | |
| while (*str != '\0') { | |
| if (*str == c) | |
| n++; | |
| str++; | |
| } | |
| return n; | |
| } | |
| void replSpace(char *str, char c) | |
| { | |
| while (*str != '\0') { | |
| if (*str == ' ') | |
| *str = c; | |
| str++; | |
| } | |
| } | |
| void fillStruct(struct Personal *ptr) | |
| { | |
| printf("Vorname: "); | |
| scanf("%s", ptr->Vorname); | |
| printf("Nachname: "); | |
| scanf("%s", ptr->Nachname); | |
| int alter; | |
| printf("Alter: "); | |
| scanf("%d", &alter); | |
| ptr->Alter = alter; | |
| double gehalt; | |
| printf("Gehalt: "); | |
| scanf("%lf", &gehalt); | |
| ptr->Gehalt = gehalt; | |
| } | |
| void sortNumbers(int *arr, int len) | |
| { | |
| int tmp; | |
| for (int i = len - 1; i >= 0; i--) { | |
| for (int j = 0; j < i; j++) { | |
| if (arr[j] < arr[j + 1]) { | |
| tmp = arr[j]; | |
| arr[j] = arr[j + 1]; | |
| arr[j + 1] = tmp; | |
| } | |
| } | |
| } | |
| for (int i = 0; i < len; i++) | |
| printf("%d\n", arr[i]); | |
| } | |
| int main(void) | |
| { | |
| // 2) | |
| char test[20] = "Hello World!"; | |
| replSpace(test, '_'); | |
| printf("%s\n", test); | |
| // 3) | |
| printf("%d\n", countLetter(test, 'l')); | |
| // 4 + 5) | |
| struct Personal *p; | |
| p = malloc(sizeof(struct Personal)); | |
| fillStruct(p); | |
| printf("Vorname: %s\nNachname: %s\nAlter: %d\nGehalt: %.2f\n", | |
| p->Vorname, p->Nachname, p->Alter, p->Gehalt); | |
| // 6) | |
| int arr[] = { 3, 2, 1, 6, 5, 4 }; | |
| sortNumbers(arr, sizeof(arr)/sizeof(arr[0])); | |
| return 0; | |
| } | |
| // vim: set ft=c : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment