Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdarg.h>
- int cmp(const void *p1, const void *p2) {
- return *(int*)p1 - *(int*)p2;
- }
- void vaSort(int n, ...) {
- va_list va;
- va_start(va, n);
- int *arr = calloc(sizeof(int), n);
- if (arr == NULL) {
- perror("");
- exit(EXIT_FAILURE);
- }
- for (int i = 0; i < n; i++) {
- arr[i] = *va_arg(va, int*);
- }
- qsort(arr, n, sizeof(*arr), cmp);
- va_start(va, n);
- for (int i = 0; i < n; i++) {
- *va_arg(va, int*) = arr[i];
- }
- free(arr);
- va_end(va);
- }
- int main(int argc, char *argv[]) {
- int a = 2, b = 3, c = 1;
- vaSort(3, &a, &b, &c);
- printf("%d %d %d\n", a, b, c);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement