pointer array

Hello,
I am having trouble swaping values in pointer array.

here is my code

1
2
3
4
5
6
7
8
9
10
11
12
13
void sort(int *list, int count){
               int i;
          for (i=0; i < count; i++) {
        fscanf(file, "%i", &number); 
        *(list+i)= number; 
        } 
      
}

void swap(int *list, int *sw) {
     
     
}


From the sort function I have to use the swap function to relocate the values in the pointer array from least to greatest.

Please if anyone could help me out that would be great.
I don't understand you want to swap the list param with the sw param?
What I have to do is that the integer values stored in the pointer array *(list+i) , I have to order them from least to greatest. For instance if (1,3,6,7,4) is stored in the *(list+i) i have to use the swap function to rearrange the order of the values from least to greatest.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdlib.h>
#include <stdio.h>
#define SIZEOFARRAY(array, type) sizeof(array)/sizeof(type)

void sort(int * array, int count){
	int aux;
	int i,j;

	for(i = 2; i<=count;i++){
		for(j=0; j<=(count-i);j++){
			if(array[j] > array[j+1]){
				aux = array[j];
				array[j] = array[j+1];
				array[j+1] = aux;
			}
		}
	}
}

int main(){
	char a;
	int array[3];

	array[0] = 5;
	array[1] = 6;
	array[2] = 4;

	sort(array, SIZEOFARRAY(array, int)); // SIZEOFARRAY returns 3

	for(int i=0;i<SIZEOFARRAY(array, int);i++)
		printf("%d\n", array[i]);

	scanf("%c", &a);

	return 0;
}
Topic archived. No new replies allowed.