So I'm trying to sort an array of pointers as seen below. The problem I have is that the array contains one null element. I have to dereference all the elements except NULL other wise i get an error of course, but this causes my sort to not properly sort any elements after NULL appears. I can create a specific exception for a NULL case, but is there anyway to avoid this, and treat NULL at 0 while I still dereference everything else? right now i tell the sort to ignore NULL. This is just a place holder as I have been unable to find a solution to my problem.
#include <stdio.h>
#include <stdlib.h>
void arr(int ar[], int ele);
int main(){
int a=0, b=9, x=3, p=2, *ar[]={&a, &b, &x, NULL, &p}, i=0, ele=(sizeof(ar)/sizeof(ar[0]));
arr(ar, ele);
printf("\n\n");
for(;i<ele;i++){
if(ar[i]==NULL){
printf("");
}else{
printf("%i", *ar[i]);
}
}
}
void arr(int *ar[], int ele){
int i=ele-1, c=0;
for(;i>0; i--){
for(;c<i; c++){
if((ar[c]!=NULL && ar[c+1]!=NULL) && *ar[c]>*ar[c+1]){
int t=*ar[c+1];
*ar[c+1]=*ar[c];
*ar[c]=t;
}
}
}
}