Hey guys im gettin an assignment makes integer from pointer without a cast?
im trying to store anInt into the data
Code:
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
typedef struct listNode
{
int data;
struct listNode * next;
}ListNode;
typedef ListNode * ListNodePtr;
int main(void)
{
ListNodePtr head, new, current, previous, next;
unsigned listSize;
int i, anInt;
listSize = 0;
head = NULL;
while(scanf("%d", &anInt) == 1)
{
if((new = malloc(sizeof(ListNode)))==NULL)
{
fprintf(stderr,
"\nmemory allocation forlist insert failed\n");
fprintf(stderr, "aborting data entry\n");
break;
}
current = head;
previous = NULL;
while(current !=NULL && current->data < anInt)
{
previous = current;
current = current->next;
}
new->data = anInt;
new->data = current;
listSize++;
if(previous == NULL)
{
head = new;
}
else
{
previous->next = new;
}
}/*end of major while loop*/
/*display integers in linked list*/
current = head;
while(current !=NULL)
{
printf("%d\n", current->data);
current = current->next;
}
/*deallocate memory here*/
current = head;
while(current !=NULL)
{
next = current->next;
free(current);
current = next;
}
return EXIT_SUCCESS;
}