hello all.
I don't know why it output twice in "Node-data[%d]",so irritancy!
header file
Code:
/* this a header file for list.c */
/* file name: head-list.h */
/* author:mycount */
/* time:12:03 */
#define LEN sizeof(link)
typedef struct list
{
char data;
struct list * next;
}link;
my code:
Code:
/* this is a c programm */
/* file name:list.c */
#include "head-list.h"
#include <stdio.h>
#include <stdlib.h>
/* above is include files which are concerned in use */
link *create(void)
{
link * head;
head=NULL;
head=(link *)malloc(LEN);
if(head!=NULL)
{
return head;
}
else
{
exit(0);
}
}/* this function is create a list */
link *Init(link *head,int num)
{
int flag=1;
head->data=0;
link *p,*q;
while(num--)
{
if(flag==1)
{
p=(link *)malloc(LEN);
head->next=p;
printf("\nfollowing is initialize the link list\n\nplease input the node'data.\n");
printf("Node-data[%d]",flag);
p->data=getchar();
}
else
{
printf("\n");
p=(link *)malloc(LEN);
printf("Node-data[%d]",flag);
p->data=getchar();
}
q=p;
p=p->next;
q->next=p;
flag++;
}
q->next=NULL;
return head;
}/* this function is initialize a list */
void disp(link *h)
{
while(h!=NULL)
{
h=h->next;
printf("%c",h->data);
}
}/* this function is display the list */
/* following is main function */
int main(void)
{
link * head;
link * init_head;
head=create();
init_head=Init(head,5);
disp(init_head);
}//end