]> gitweb.hhaalo.de Git - discspan.git/commitdiff
change: array with realloc
authorBastian Dehn <hhaalo@arcor.de>
Sun, 1 Oct 2017 20:38:38 +0000 (22:38 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 1 Oct 2017 20:38:38 +0000 (22:38 +0200)
discspan.c

index fe3429cc23e0b601bc7cae6188ba9ed09a07f22c..3295ff40370f97d601710b06901db7e8bd9846d6 100644 (file)
@@ -101,16 +101,16 @@ void splitter(const char *input,
        printHumanReadSize(output, splitgroesse);
 }
 
-int cmpfunc(const void * filea,
-                       const void * fileb) {
-       long long unsigned int a = ((const struct file_size*)filea)->fsize;
-       long long unsigned int b = ((const struct file_size*)fileb)->fsize;
+int cmpfunc(const void *filea,
+                       const void *fileb) {
+       long long unsigned int a = ((const struct file_size*) filea)->fsize;
+       long long unsigned int b = ((const struct file_size*) fileb)->fsize;
 
        if (a < b) {
                return 1;
-       } else if(a > b) {
+       } else if (a > b) {
                return -1;
-       } else if(a == b) {
+       } else if (a == b) {
                return 0;
        } else {
                return -2;
@@ -137,7 +137,8 @@ void filesize_sort(const char *input,
        fseek(in, 0L, SEEK_SET);
 
        // struct Array with Dateienanzahl
-       struct file_size fs[lines -1];
+       struct file_size *fs = NULL;
+       fs = (struct file_size *) malloc((lines -1) * sizeof(struct file_size));
        lines = 0;
 
        while (fscanf(in, "%[^\n]\n", pfad) == 1) {
@@ -160,6 +161,8 @@ void filesize_sort(const char *input,
                }
        }
 
+       fs = (struct file_size *) realloc(fs, (lines+1) * sizeof(struct file_size));
+
        // sortiere das array fs mit stucts
        qsort(fs, lines, sizeof(struct file_size), cmpfunc);