I have the following function
typedef struct userDataStruct
{
char name [MAX_NAME_LENGTH+1];
struct userDataStruct *next;
} userDataType;
errorType GetUsers (userDataType **list)
{
FILE *file;
char buffer [LINE_LENGTH+1];
userDataType *first, *previous, *new;
file = fopen ("abc.dat", "r");
first = previous = NULL;
while (fgets (buffer, LINE_LENGTH+1, file))
{
new = (userDataType *) malloc (sizeof (userDataType));
/* Resto do codigo */
if (first == NULL)
first = new;
if (previous != NULL)
previous->next = new;
previous = new;
}
list = &first;
return ok;
}
(ignore any syntax errors, I had to wipe)
When I need to call this function, I declare a pointer and step it with the null value. For example:
int main (void)
{
userDataType **usersList = NULL,
*currentUser;
GetUsers(usersList);
currentUser = *usersList; /* Aqui está o erro */
}
In the line indicated, the variable currentUser is null.
If I used the malloc function to allocate memory, should that variable not be pointing to the first element in the list?
Thank you in advance.