0

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();
}

1 Answers1

2
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.

Gopi
  • 19,784
  • 4
  • 24
  • 36
  • @imagineracoon Oh that is a different thing .. Keep the head of the list intact and print your list from head to end of list .. (Did you get what I just said?) – Gopi Feb 03 '15 at 14:29
  • @imagineracoon Really that is a different thing all together you need to post another question with what you actually want – Gopi Feb 03 '15 at 14:31
  • Ok. I will search about that. If nothing, ill post. – imagineracoon Feb 03 '15 at 14:34