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 */

> linklist=(list *)malloc(sizeof(list));
This is a C program, and you're casting the result of malloc.
You don't need to do this in C.
See
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1047673478&id=1043284351

> scanf("%d",linklist->data);
1. You forgot the &
2. it's %c for reading chars, %d is for ints

> p1=(list *)malloc(sizeof(list));
On the last iteration of the loop, your node remains uninitialised.

Thanks Dave and Salem so.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.