0

So I've a method in which I'm trying to see which linked list is larger. If I find the larger one than I want to set a pointer to it, so when I do my arithmetic on the linked list I am subtracting the smaller from the larger, no matter if it is linked list A or linked list B. I've having some problems though. First of all when I see if there is data in my newly assigned pointer I get an error saying "invalid type argument of ‘->’ (have ‘struct node’)" Here is my code, any help would be much appreciated!

void subtraction(struct node** headOne, struct node** currOne, struct node** tailOne, struct node** headTwo, struct node** currTwo, struct node** tailTwo, struct node** headThree, struct node** tailThree, int lengthOne, int lengthTwo){
int numberOne, numberTwo, diff;
struct node* longest;
struct node* shortest;
printf("tailOne data = %d\n",(*tailOne)->data);
    printf("tailTwo data = %d\n",(*tailTwo)->data);
if(lengthTwo > lengthOne){
    longest = *currTwo;
    shortest = *currOne;
}
else if (lengthOne > lengthTwo){
    longest = *currOne;
    shortest = *currTwo;
}
else{
    if(((*tailOne)->data) > ((*tailTwo)->data)){
        longest = *currOne;
        shortest = *currTwo;
    }
    else{
        longest = *currTwo;
        shortest = *currOne;
    }
}
while(longest){
    printf("longest = %d",(*longest)->data);
}

}

int main(){
//initials
int i, number, lengthOne, lengthTwo; 
char ch = 1;
//node pointers
struct node* headOne = NULL;
struct node* currOne = NULL;
struct node* tailOne = NULL;
struct node* headTwo = NULL;
struct node* currTwo = NULL;
struct node* tailTwo = NULL;
struct node* headThree = NULL;
struct node* currThree = NULL;
//create linked list
lengthOne = createLL(&headOne,&currOne, &tailOne, ch, number);
lengthTwo = createLL(&headTwo,&currTwo, &tailTwo, ch, number);
scanf("%c",&ch);
if (ch == '+'){
addition(&headOne, &currOne, &headTwo, &currTwo, &headThree, &currThree, lengthOne, lengthTwo);
}
else if(ch == '-'){
subtraction(&headOne, &currOne, &tailOne, &headTwo, &currTwo, &tailTwo, &currThree, &headThree, lengthOne, lengthTwo);
}
2
  • That function prototype is insane. 10 parameters? That's surely a sign you are combining way too many things into one function. Commented Feb 14, 2016 at 4:25
  • I agree with some better design I could shrink the parameters quite a bit but I'm more focused on pointers and linked list at the moment. Commented Feb 14, 2016 at 4:34

1 Answer 1

1

It should be longest->data or (*longest).data, not (*longest)->data.

Sign up to request clarification or add additional context in comments.

1 Comment

That worked!! I guess I'm just completely confused by pointers. Thanks though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.