Since your pInt variable is already a pointer, and scanf takes a pointer argument, you should not be using the "address of" operator here. Take it out. Try this:
Yup Your right it works.. Thanks! This wasn't a good example of the problem I am having then. D'oh. The following code is probably pretty familiar to a few by now..
I call the following function in this manner:
Code:
insert(pMylist, pData, sizeof(pData));
Now, if pData is a pointer of type struct it works. If it is a pointer of type int, it does not work. This function has to be generic!!! But from what I can tell calling memcpy like this:
Code:
// ..works in the following function if pData is struct * data type
memcpy(pNewnode->data, pData, size);
// ..works in the following function if pData is int * data type
memcpy(&pNewnode->data, pData, size);
Code:
int insert(DLL *pRoot, void *pData, size_t size)
{
NODE *pNewnode;
// Allocate memory for the next node in the list
if ((pNewnode = (NODE *) malloc(sizeof(NODE))) == NULL)
{
printf("Error: Unable to allocate memory for pNewnode");
fflush(stdout);
exit(EXIT_FAILURE);
}
// Allocate memory for the input from user
if ((pNewnode->data = malloc(size)) == NULL)
{
printf("Error: Unable to allocate memory for pNewnode->data");
fflush(stdout);
exit(EXIT_FAILURE);
}
pNewnode->next = NULL;
pNewnode->prior = NULL;
// Copy the data to the new node: This bit currently broken
memcpy(pNewnode->data, pData, size);
if (pRoot->head == NULL)
{
pRoot->head = pNewnode;
pRoot->tail = pNewnode;
pRoot->count = 1;
}
else
{
pNewnode->prior = pRoot->tail;
pRoot->tail->next = pNewnode;
pRoot->tail = pNewnode;
pRoot->count += 1; // Increase the count for the number of nodes
}
return 1;
}