Reputation: 27
I am trying to implement singly linked list. Is this correct? Getting this warning "non portable pointer conversion". How do i check if the SLL is working? Is it connected to each other? By the way, I am using Turbo C. I am still in this creating and inserting the nodes part.
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
}*start=NULL;
void creat(int *num)
{
struct node *new_node,*current;
new_node=(struct node *)malloc(sizeof(struct node));
new_node->data=num;
new_node->next=NULL;
if(start==NULL)
{
start=new_node;
current=new_node;
}
else
{
current->next=new_node;
current=new_node;
}
}
main()
{
int binrange,max=100,n,i,divi;
clrscr();
printf("enter range: ");
scanf("%d",&binrange);
n=max/binrange;
divi=max/n;
for(i=0;i<=max;i++)
{
if(i%divi==0 && i>0)
{
//create nodes here
//store i into nodes
creat(&i);
}
}
getch();
}
Upvotes: 0
Views: 59
Reputation: 19874
new_node->data=num;
should be
new_node->data=*num;
num
is a pointer and *num
gives the value to be stored in the new_node->data
Assigning pointer to a variable of type int
is giving a valid warning.
Upvotes: 2