您的位置首页百科问答

c语言程序设计实例

c语言程序设计实例

#include#include咐侍#define MAX 100struct addr{ char name[30]; char street[40]; char city[20]; char state[3]; unsigned long int zip;}add_list[MAX];void init_list(void),enter(void);void delete(void),list(void);void load(void),save(void);int menu_select(void),find_free(void);int main(void){ char choice; init_list();/*initialize the structure array*/ for(;;){ choice=menu_select(); switch(choice){ case 1:enter(); break; case 2:delete(); break; case 3:list(); break; case 4:save(); break; case 5:load(); break; case 6:exit(0); } } return 0;}/*Initialize the list*/void init_list(void){ register int t; for(t=0;t6); return c; }/*Input addresses into the list*/void enter(void){ int slot; char s[80]; slot=find_free(); if(slot==-1){ printf("\nList Full"咐橘); return; } printf("Enter name:"); gets(add_list[slot].name); printf("Enter street:"); gets(add_list[slot].street); printf("Enter city:"); gets(add_list[slot].city); printf("Enter state:"); gets(add_list[slot].state); printf("Enter zip:"); gets(s); add_list[slot].zip=strtoul(s,'\0',10); }/*Find an unused structure*/int find_free(void){ register int t; for(t=0;add_list[t].name[0]&&t=0&&slot