struct node
{
char *IPArray[100];
struct node *ptr;
};
typedef struct node NODE;
NODE *head, *first, *temp = 0;
first = 0;
int numofIP;
This is my structure to contain string at every node in a linked list. And numofIP is maximum number of strings or nodes in my linked list.
for(int i=0; i<numofIP; i++)
{
head = (NODE *)malloc(sizeof(NODE));
printf("enter the IP addresses:\n");
scanf("%s",&head->IPArray[i]);
if(first != 0)
{
temp->ptr = head;
temp = head;
}
else
{
first = temp = head;
}
}
temp->ptr = 0;
temp = first;
this is how I accept input and store it in every node.
while(temp != NULL)
{
printf("%d=> ",temp->IPArray);
temp = temp->ptr;
}
And this is how I print the linked list.
But problem is I get addresses in output. I am not able to figure it out. How to store a string in each node in a linked list?