01/10/2018, 08:38 
               
            Mọi người xem hộ em nhập vào và in ra danh sách liên kết với ạ. em sai ở đâu mà chạy toàn bị treo
#include <stdio.h>
#include <stdlib.h>
struct node
{
   char ten[30];
   int tuoi;
   struct node *next;
};
struct node *head = NULL;
void nhap(int a)
{
    int i;
   struct node *ptr;
  ptr=(struct node*) malloc(a*sizeof(struct node));
   for(i=0;i<a;i++)
    {
      printf("Nhap ten");
      fflush(stdin);
      gets((ptr+i)->ten);
      printf("
nhap tuoi");
      fflush(stdin);
      scanf("%d",&(ptr+i)->tuoi);
   }
head=ptr;
}
void xuat(int a)
{
    struct node *i;
    i=head;
    while(i!=NULL)
    {
        printf("
%-30s|%5d",i->ten,i->tuoi);
        i = i->next;
    }
}
void main()
{
int a;
printf("Nhap so luong");
scanf("%d",&a);
nhap(a);
xuat(a);
return 0;
}
            Bài liên quan
         
                
            



