Hi,all.I want to know why this program can not run faultlessly?
Thanks to all.

#include <stdio.h>
#include <stdlib.h>
 
typedef struct link{
 char data;
 struct link * next;
 struct link * pre;
}list;      
     
main()
{
 list * head=NULL; /* Define the head node */
 list * linklist;  /* Define the link list */
 list * p1,* p2; /* Define tempopary node */
 char flag;         /* Define the sign*/
 int count;         /* Define the member count*/
 
 printf("Input count of data-member\n");
 printf("count:");
 scanf("%d",&count);
 
 linklist=(list *)malloc(sizeof(list));
    head->pre=NULL;
 head->next=linklist;
 p1=NULL;
 
 printf("Input member's data\n");
 for(int i=0;i<count;i++)
 {
  printf("Member%d :",i+1);
  scanf("%d",linklist->data);
  p1=(list *)malloc(sizeof(list));
  linklist->next=p1;
  p1->pre=linklist;
  linklist=p1;
 }

 linklist->next=NULL;
 p2=head->next;
 i=0;

 while(p2!=NULL)
 {
  printf("Node[%d] :",i++);
  printf("%c",p2->data);
  p2=p2->next;
 }
 
}
#include <stdio.h>
#include <stdlib.h>

typedef struct link
{
   char data;
   struct link * next;
   struct link * pre;
}list;      

main()
{
   list * head=NULL; /* Define the head node */
   list * linklist;  /* Define the link list */
   list * p1,* p2; /* Define tempopary node */
   char flag;         /* Define the sign*/
   int i,count;         /* Define the member count*/

   printf("Input count of data-member\n");
   printf("count:");
   scanf("%d",&count);

   linklist=(list *)malloc(sizeof(list));
   head->pre=NULL; /* Likely use of null pointer 'head' in left argument to operator '->' */
   head->next=linklist; /* Likely use of null pointer 'head' in left argument to operator '->' */
   p1=NULL;

   printf("Input member's data\n");
   for ( i=0;i<count;i++ )
   {
      printf("Member%d :",i+1);
      scanf("%d",linklist->data); /* argument no. 2 should be a pointer,
      Possible use of null pointer 'linklist' in left argument to operator '->' */
      p1=(list *)malloc(sizeof(list));
      linklist->next=p1; /* Possible use of null pointer 'linklist' in left argument to operator '->' */
      p1->pre=linklist; /* Possible use of null pointer 'linklist' in left argument to operator '->' */
      linklist=p1;
   }

   linklist->next=NULL; /* Possible use of null pointer 'linklist' in left argument to operator '->' */
   p2=head->next; /* Likely use of null pointer 'head' in left argument to operator '->'
   Possible use of null pointer 'linklist' in left argument to operator '->' */
   i=0;

   while ( p2!=NULL )
   {
      printf("Node[%d] :",i++);
      printf("%c",p2->data);
      p2=p2->next;
   }

} /* function 'main(void)' should return a value */
/* Symbol 'flag' (line 16) not subsequently referenced */
This article has been dead for over six months. Start a new discussion instead.