đây là bài ví dụ trong sách nhưng có vài chỗ mình ko hiểu vs tại sao nó lại ko đưa ra được danh sách
Mã:
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
struct dia_chi
{
char ten[30];
int so_nha;
char pho[20];
char thanh_pho[15];
}addr[MAX];
void init_list(void);
void enter(void);
void delete(void); /*sao lai dung duoc delete va list de dat ten vay ??*/
void list(void);
int menu_select(void);
int find_free(void);
main()
{
char choice;
init_list();
for(;;)
{
choice=menu_select();
switch(choice)
{
case 1 :enter();break;
case 2 :delete();break;
case 3 :list();break;
case 4 :exit(0);
}
}
}
void init_list(void)
{
register int t;
for(t=0;t<MAX;t++)addr[t].ten[0] = '\0';
}
int menu_select(void)
{
char s[80];
int c;
printf("
");
printf("1.vao ten
");
printf("2.xoa ten
");
printf("3.danh sach
");
printf("4.ket thuc
");
do
{
printf("
hay cho lua chon cua ban: "); /*hoat dong cua lenh do...while nay la ntn vay??*/
gets(s);
c=atoi(s);
}while(c<0||c>4);
return c;
}
void enter(void)
{
int slot;
char s[80];
slot=find_free();
if(slot==-1)
{
printf("
Danh sach het cho.");
return;
}
printf("Ten: ");
scanf("%d",&addr[slot].so_nha);
while(getchar()!='
'); /* sao while cut nhu the nay*/
printf("ten pho: ");
gets(addr[slot].pho);
printf("ten thanh pho: ");
gets(addr[slot].thanh_pho);
}
int find_free(void)
{
register int t;
for(t=0;addr[t].ten[0]&&t<MAX;t++)
if(t==MAX) return -1;
return t;
}
void delete(void)
{
register int slot;
char s[80];
printf("hay cho biet so ban ghi: ");
gets(s);
slot=atoi(s);
if(slot>0&&slot<MAX)
addr[slot].ten[0]='\0';
}
void list( void)
{
register int t;
for (t=0;t<MAX;t++)
{
if(addr[t].ten[0])
{
printf("%s
",addr[t].ten);
printf("%s
",addr[t].so_nha);
printf("%s
",addr[t].pho);
printf("%s
",addr[t].thanh_pho);
}
}
printf("
");
}
nhân tiện ai có tài liệu về phần kiểu dữ liệu cấu trúc cho mình xin 1 bản [IMG]images/smilies/biggrin.png[/IMG]
Pallet nhựa Long An đã trở thành một trong những lựa chọn phổ biến cho nhu cầu vận chuyển và lưu trữ hàng hóa trong nhiều ngành công nghiệp. Với đặc tính nhẹ nhàng, chắc chắn và dễ vận chuyển, các...
Thanh lý pallet nhựa Long An giá rẻ