Hi all, I was trying to implement the solution into C code, but changed bunch of times still getting errors.

Could someone give me some suggestions on my code?

I really appreciate your help.

Thanks!

```
struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) {
struct ListNode *p1 = headA;
struct ListNode *p2 = headB;
int a_end = 1;
int b_end = 1;
if (!p1 || !p2) return NULL;
while(1) {
int a = p1->val;
int b = p2->val;
if(a == b) return p1;
p1 = p1->next;
p2 = p2->next;
if(!p1) {
p1 = headB;
p2 = p2->next;
a_end = a;
}
if(!p2) {
p2 = headA;
p1 = p1->next;
b_end = b;
}
if(a_end != b_end) return NULL;
}
```