The problem is that after the addapplicant() function has run and the program return to main i test it by printing the values in the structure but i get null for both. But before hand in the function i get whatever i put in. Can anyone help me. I believe it is a problem with pointers or soemthing
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct clientNode {
char *name;
char *address;
clientNode *link;
};
void addApplicant(clientNode *, clientNode *);
int main() {
clientNode *current;
clientNode *list;
addApplicant(current, list);
printf("%s\t%s", current->name, current->address);
}
void addApplicant(clientNode *current, clientNode *list) {
char nInput[30], aInput[40];
scanf(" %[^\n]s", nInput);
scanf(" %[^\n]s", aInput);
if (current == NULL) {
list = current = (clientNode*)malloc(sizeof(clientNode));
}
else {
current->link = (clientNode*)malloc(sizeof(clientNode));
current = current->link;
}
current->link = NULL;
current->name = (char*)malloc(strlen(nInput)+1);
strcpy(current->name, nInput);
current->address = (char*)malloc(strlen(aInput)+1);
strcpy(current->address, aInput);
printf("%s\t%s", current->name, current->address);
}