Your function makes little sense as you're trying to return values from a function with void return type;
Something like this might work for you:
#include <stdlib.h>
#include <stdio.h>
typedef struct list
{
int data;
list* next;
} list;
list* add_node(list* root, int data) {
list* node = (list*)malloc(sizeof(node));
node->data = data;
node->next = NULL;
if (root != NULL) {
list* ptr = root;
while(ptr->next != NULL) {
ptr = ptr->next;
}
ptr->next = node;
}
return node;
}
void delete_list(list* root)
{
list* ptr = root;
while(ptr != NULL) {
list* node = ptr;
ptr = ptr->next;
free(node);
}
}
void print_list(list* root) {
list* ptr = root;
while(ptr != NULL) {
printf("%d->", ptr->data);
ptr = ptr->next;
}
}
void add_list(list*l1, list* l2)
{
list *l1Ptr = l1;
list *l2Ptr = l2;
int carry = 0;
list *result = NULL;
while(l1Ptr != NULL && l2Ptr != NULL) {
int sum = l1Ptr->data + l2Ptr->data + carry;
if (sum > 9) {
sum %= 10;
carry = 1;
}
if (result == NULL)
result = add_node(result, sum);
else
add_node(result, sum);
l1Ptr = l1Ptr->next;
l2Ptr = l2Ptr->next;
}
printf("Result: ");
print_list(result);
printf("\r\n");
}
int main(int argc, char* argv[])
{
list* l1 = add_node(NULL, 3);
add_node(l1, 4);
add_node(l1, 5);
list* l2 = add_node(NULL, 1);
add_node(l2, 6);
add_node(l2, 3);
printf("List 1: ");
print_list(l1);
printf("\r\n");
printf("List 2: ");
print_list(l2);
printf("\r\n");
add_list(l1, l2);
return 0;
}
Hope this helps,
Fredrik