Not really; you've got two choices:
Option 1: return void, change the parameter
Code:
void removePtr(LIST_ELEM **pHead, int loc) {
LIST_ELEM *prevPtr, *nextPtr, *tempPtr;
int size = sizeOf(*pHead);
if (loc == 0) {
if (size == 0) return; //already empty
prevPtr = (*pHead)->next;
free(*pHead);
*pHead = prevPtr;
return;
}
if (size < loc) return; //can't delete element that doesn't exist
//if we're still here then walk to the element and delete it
tempPtr = *pHead;
for (int i = 0; i < loc; i++) {
tempPtr = tempPtr->next;
}
prevPtr = nodeB4(*pHead, loc); //if we didn't have the function, we'd walk prevPtr with tempPtr
nextPtr = tempPtr->next;
prevPtr->next = nextPtr;
free(tempPtr);
return;
}
Option 2, return the head of the list (consistent with your add)
Code:
LIST_ELEM *removePtr(LIST_ELEM *pHead, int loc) {
LIST_ELEM *prevPtr, *nextPtr, *tempPtr;
int size = sizeOf(pHead);
if (loc == 0) {
if (size == 0) return NULL; //already empty
prevPtr = pHead->next;
free(pHead);
pHead = prevPtr;
return pHead;
}
if (size < loc) return pHead; //can't delete element that doesn't exist
//if we're still here then walk to the element and delete it
tempPtr = pHead;
for (int i = 0; i < loc; i++) {
tempPtr = tempPtr->next;
}
prevPtr = nodeB4(pHead, loc); //if we didn't have the function, we'd walk prevPtr with tempPtr
nextPtr = tempPtr->next;
prevPtr->next = nextPtr;
free(tempPtr);
return pHead;
}
I've assumed you still don't want loc==0 to kill the whole list. EDIT: Also I haven't tested it, or even compiled it, so caveat lector.