Sorting an array using pointers 
Author Message
 Sorting an array using pointers

How does one sort an array of integers using pointers. Help appr. here
what I have so far.

int main ()
{
        #define MAXVAL 100

        int table_fill(int a[], int max);

        void print_table(int a[], int max);
        int t[MAXVAL];
        int n = table_fill(t, MAXVAL);

        print_table(t, n);
        return 0;

Quote:
}

#include <stdio.h>

int table_fill(int a[], int max)
{
        int *ptr = a;
        int *endptr = ptr + max;
        int r;

        for(ptr = a; (r = scanf("%i", ptr)) != EOF && *ptr >= 0 && ptr <
endptr;
                        ptr++)
        {
                if (r != 1)
                        break;
                if (ptr == endptr)
                        break;
        }

        return (int)(ptr - a);

Quote:
}

void  print_table(int a[], int max)
{
        int *endptr = a + max;
        int *ptr = a;

        while (ptr < endptr)
        {
                printf("%i\n", *ptr);
                ptr++;
        }

Quote:
}



Thu, 12 Aug 1999 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. sorting an array using pointers

2. Can I sort a structured array using Array.Sort? USING C#

3. Can I sort a structured array using Array.Sort? USING C#

4. Can I sort a structured array using Array.Sort? Using C#

5. Sorting array of pointers to int

6. Sorting an Array of pointers to structures

7. pointers, arrays and sorting

8. sorting , pointers and arrays

9. soritng a const char[][50] array using sort ?

10. Help using qsort to sort pointers to a structure

11. I want to be able to sort the program using pointer and structure in C progr

12. Dereferencing f-pointers, arrays of f-pointers, pointers to f-pointers

 

 
Powered by phpBB® Forum Software