当前位置: 首页 > news >正文

电子商务网站建设读书报告Sierra wordpress

电子商务网站建设读书报告,Sierra wordpress,网页版微信二维码几分钟失效,简易签名设计一笔签本文使用了malloc、realloc、calloc等和内存开辟有关的函数。 文章目录 前言 二、头文件 三、主界面 四、通讯录功能函数 1.全代码 2.增加联系人 3.删除联系人 4.查找联系人 5.修改联系人 6.展示联系人 7.清空联系人 8.退出通讯录 总结 前言 为了使用通讯录时#xff0c;可以… 本文使用了malloc、realloc、calloc等和内存开辟有关的函数。 文章目录 前言 二、头文件 三、主界面 四、通讯录功能函数 1.全代码 2.增加联系人 3.删除联系人 4.查找联系人 5.修改联系人 6.展示联系人 7.清空联系人 8.退出通讯录 总结 前言 为了使用通讯录时可以随时调整大小所以使用动态开辟内存函数写通讯录可增加联系人容量。 动态开辟函数即在内存的栈区开辟空间所以使用完毕后需要释放内存空间。 一、通讯录运行图 二、头文件 #includestdio.h #includestring.h #includestdlib.h #includeassert.h #includestdlib.h#define Max 10enum function {quit,increase,delete,find,revise,show,empty,sort };typedef struct Person {char name[20];size_t age;char sex[5];char address[30];char phone[12]; }person;//动态 typedef struct contact {person *per;size_t sz;//通讯录已有人员个数size_t ContactMax;//通讯录当前最大容量 }contact;void init_contact(contact* con);void increase_contact(contact* con);void delete_contact(contact* con);//return -1(no) / address(yes) int find1(const contact** con, size_t choice); void find_contact(const contact* con);void revise_contact(contact* con);void show_contact(const contact* con); //排序通讯录 void sort_contact(contact* con); //销毁通讯录 void destroy_contact(contact* con);三、主界面 #include contact.hvoid menu1() {printf(**************************************\n);printf(******* Simplified address book ******\n);printf(******* 1 increase contact ******\n);printf(******* 2 delete contact ******\n);printf(******* 3 find contact ******\n);printf(******* 4 revise contact ******\n);printf(******* 5 Show all contacts ******\n);printf(******* 6 Empty all contacts ******\n);printf(******* 7 Sort by name ******\n);printf(******* 0 Quit Contacts ******\n);printf(**************************************\n); }void test() {//create contactscontact con;//initialize contactsinit_contact(con);size_t choice 0;do{menu1();printf(Enter the feature options you need:);scanf(%u, choice);switch (choice){case increase:increase_contact(con);break;case delete:delete_contact( con );break;case find:find_contact(con);break;case revise:revise_contact(con);break;case show:show_contact(con);break;case empty:init_contact(con);break;case sort:sort_contact(con);break;case quit:destroy_contact(con);printf(Exiting Contacts...\n);break;default:printf(You entered the wrong number, please re-enter it.\n);break;}} while (choice);printf(Exited Contacts.\n);}int main() {test();return 0; } 四、通讯录功能函数 1.全代码 #includecontact.hvoid menu2() {system(cls);printf(1 name \t 2 age\n);printf(3 sex \t 4 address\n);printf(5 phone\n);printf(Please select:); }//动态 void init_contact(contact* con) {assert(con);// per sz ContactMaxcon-sz 0;person* p (person*)calloc(Max, sizeof(person));if (p NULL){perror(init_contact::calloc);return;}con-per p;con-ContactMax Max; }void tune(contact* con) {if (con-sz con-ContactMax){person *p (person *)realloc(con-per, (con-ContactMax Max) * sizeof(person));if (p NULL){perror(tune::realloc);return;}con-per p;con-ContactMax Max;} }//动态开辟 void increase_contact(contact* con) {assert(con);//检测当前通讯录是否需要增容tune(con);printf(name:);scanf(%s, (con-per[con-sz].name));printf(age:);scanf(%u, (con-per[con-sz].age));printf(sex:);scanf(%s, (con-per[con-sz].sex));printf(address:);scanf(%s, (con-per[con-sz].address));printf(phone:);scanf(%s, (con-per[con-sz].phone));(con-sz); }void delete_contact(contact* con) {assert(con);menu2();size_t choice 0;size_t result 0;while (1){scanf(%u, choice);if (choice 5 choice 1){result find1(con, choice);break;}else{printf(Your input is incorrect, please re-enter it:);}}if (result ! -1){char true[5] { 0 };printf(Are you sure you want to delete %ss information?, con-per[result].name);printf(yes/no:);scanf(%s, true);if (!strcmp(true, yes)){if ( con-sz ){memmove(con-per[result].name, con-per[(con-sz) - 1].name, sizeof(con-per[0]));}else{memset(con-per[result].name, 0, sizeof(con-per[0]));}(con-sz)--;printf(The deletion was successful, thanks for using!\n); }else{printf(Delete failed, please try again!\n);}}else{printf(Delete failed, please try again!\n);} }int find1(const contact** con, size_t choice) {assert(con);size_t i 0;char sample1[30] { 0 };size_t sample2 0;printf(Please enter:);switch (choice){case 1:case 3:case 4:case 5:scanf(%s, sample1);break;case 2:scanf(%u, sample2);break;}switch (choice){case 1:while (i (*con)-sz){if (!strcmp(sample1, (*con)-per[i].name)){return i;}else{i;}}break;case 3:while (i (*con)-sz){if (!strcmp(sample1, (*con)-per[i].sex)){return i;}else{i;}}break;case 4:while (i (*con)-sz){if (!strcmp(sample1, (*con)-per[i].address)){return i;}else{i;}}break;case 5:while (i (*con)-sz){if (!strcmp(sample1, (*con)-per[i].phone)){return i;}else{i;}}break;case 2:while (i (*con)-sz){if (sample2 (*con)-per[i].age){return i;}else{i;}}break;}return -1; }void find_contact(const contact* con) {assert(con);menu2();size_t choice 0;size_t result 0;while (1){scanf(%u, choice);if (choice 5 choice 1){result find1(con, choice);break;}else{printf(Your input is incorrect, please re-enter it:);}}if (result ! -1){printf(Found, the basic information of the contact is:);printf(name:%-20s\tage:%-4d\tsex:%-5s\taddress:%-30s\tphone:%-12s\n,con-per[result].name,con-per[result].age,con-per[result].sex,con-per[result].address,con-per[result].phone);}else{printf(Didnt find it!\n);}}void revise_contact(contact* con) {assert(con);menu2();size_t choice 0;size_t result 0;while (1){scanf(%u, choice);if (choice 5 choice 1){result find1(con, choice);break;}else{printf(Your input is incorrect, please re-enter it:);}}if (result ! -1){char true[5] { 0 };printf(Are you sure you want to revise %ss information?, con-per[result].name);printf(yes/no:);scanf(%s, true);if (!strcmp(true, yes)){menu2();printf(Please enter the option you want to modify:);scanf(%u, choice);char sample1[30] { 0 };size_t sample2 0;printf(Please enter:);switch (choice){case 1:case 3:case 4:case 5:scanf(%s, sample1);break;case 2:scanf(%u, sample2);break;}switch (choice){case 1:memmove(con-per[result].name, sample1, sizeof(con-per[0].name));break;case 3:memmove(con-per[result].name, sample1, sizeof(con-per[0].sex));break;case 4:memmove(con-per[result].name, sample1, sizeof(con-per[0].address));break;case 5:memmove(con-per[result].name, sample1, sizeof(con-per[0].phone));break;case 2:con-per[result].age sample2;break;}printf(The modification is complete, thanks for using!\n);}else{printf(Revise failed, please try again!\n);}}else{printf(Revise failed, please try again!\n);} }void show_contact(const contact* con) {assert(con);if ( con-sz ){size_t i 0;for (; i (con-sz); i){printf(name:%-20s\tage:%-4d\tsex:%-5s\taddress:%-30s\tphone:%-12s\n,con-per[i].name, con-per[i].age, con-per[i].sex,con-per[i].address, con-per[i].phone);}}else{printf(There is no contact information in the address book!\n);} }int cmp_char(const void* str1, const void* str2) {return strcmp(((person*)str1)-name, ((person*)str2)-name); }void sort_contact(contact* con) {qsort(con - per[0].name, con - sz, sizeof(con - per[0]), cmp_char); }void destroy_contact(contact* con) {free(con-per);con-per NULL;con-ContactMax 0;con-sz 0;con NULL; } 2.增加联系人 使用realloc()调整通讯录大小。 联系人信息图为 void tune(contact* con) {if (con-sz con-ContactMax){person *p (person *)realloc(con-per, (con-ContactMax Max) * sizeof(person));if (p NULL){perror(tune::realloc);return;}con-per p;con-ContactMax Max;} }//动态开辟 void increase_contact(contact* con) {assert(con);//检测当前通讯录是否需要增容tune(con);printf(name:);scanf(%s, (con-per[con-sz].name));printf(age:);scanf(%u, (con-per[con-sz].age));printf(sex:);scanf(%s, (con-per[con-sz].sex));printf(address:);scanf(%s, (con-per[con-sz].address));printf(phone:);scanf(%s, (con-per[con-sz].phone));(con-sz); } 3.删除联系人 通过选择联系人的某种信息例如姓名、年龄来查找需要删除的联系人找到之后确认删除该联系人。 例如: void delete_contact(contact* con) {assert(con);menu2();size_t choice 0;size_t result 0;while (1){scanf(%u, choice);if (choice 5 choice 1){result find1(con, choice);break;}else{printf(Your input is incorrect, please re-enter it:);}}if (result ! -1){char true[5] { 0 };printf(Are you sure you want to delete %ss information?, con-per[result].name);printf(yes/no:);scanf(%s, true);if (!strcmp(true, yes)){if ( con-sz ){memmove(con-per[result].name, con-per[(con-sz) - 1].name, sizeof(con-per[0]));}else{memset(con-per[result].name, 0, sizeof(con-per[0]));}(con-sz)--;printf(The deletion was successful, thanks for using!\n); }else{printf(Delete failed, please try again!\n);}}else{printf(Delete failed, please try again!\n);} } 4.查找联系人 通过联系人基础信息查找联系人。 int find1(const contact** con, size_t choice) {assert(con);size_t i 0;char sample1[30] { 0 };size_t sample2 0;printf(Please enter:);switch (choice){case 1:case 3:case 4:case 5:scanf(%s, sample1);break;case 2:scanf(%u, sample2);break;}switch (choice){case 1:while (i (*con)-sz){if (!strcmp(sample1, (*con)-per[i].name)){return i;}else{i;}}break;case 3:while (i (*con)-sz){if (!strcmp(sample1, (*con)-per[i].sex)){return i;}else{i;}}break;case 4:while (i (*con)-sz){if (!strcmp(sample1, (*con)-per[i].address)){return i;}else{i;}}break;case 5:while (i (*con)-sz){if (!strcmp(sample1, (*con)-per[i].phone)){return i;}else{i;}}break;case 2:while (i (*con)-sz){if (sample2 (*con)-per[i].age){return i;}else{i;}}break;}return -1; }void find_contact(const contact* con) {assert(con);menu2();size_t choice 0;size_t result 0;while (1){scanf(%u, choice);if (choice 5 choice 1){result find1(con, choice);break;}else{printf(Your input is incorrect, please re-enter it:);}}if (result ! -1){printf(Found, the basic information of the contact is:);printf(name:%-20s\tage:%-4d\tsex:%-5s\taddress:%-30s\tphone:%-12s\n,con-per[result].name,con-per[result].age,con-per[result].sex,con-per[result].address,con-per[result].phone);}else{printf(Didnt find it!\n);}}5.修改联系人 先查找再修改。 可以修改联系人的任一信息。 void revise_contact(contact* con) {assert(con);menu2();size_t choice 0;size_t result 0;while (1){scanf(%u, choice);if (choice 5 choice 1){result find1(con, choice);break;}else{printf(Your input is incorrect, please re-enter it:);}}if (result ! -1){char true[5] { 0 };printf(Are you sure you want to revise %ss information?, con-per[result].name);printf(yes/no:);scanf(%s, true);if (!strcmp(true, yes)){menu2();printf(Please enter the option you want to modify:);scanf(%u, choice);char sample1[30] { 0 };size_t sample2 0;printf(Please enter:);switch (choice){case 1:case 3:case 4:case 5:scanf(%s, sample1);break;case 2:scanf(%u, sample2);break;}switch (choice){case 1:memmove(con-per[result].name, sample1, sizeof(con-per[0].name));break;case 3:memmove(con-per[result].name, sample1, sizeof(con-per[0].sex));break;case 4:memmove(con-per[result].name, sample1, sizeof(con-per[0].address));break;case 5:memmove(con-per[result].name, sample1, sizeof(con-per[0].phone));break;case 2:con-per[result].age sample2;break;}printf(The modification is complete, thanks for using!\n);}else{printf(Revise failed, please try again!\n);}}else{printf(Revise failed, please try again!\n);} } 6.展示联系人 展示所有联系人及其所有信息。 void show_contact(const contact* con) {assert(con);if ( con-sz ){size_t i 0;for (; i (con-sz); i){printf(name:%-20s\tage:%-4d\tsex:%-5s\taddress:%-30s\tphone:%-12s\n,con-per[i].name, con-per[i].age, con-per[i].sex,con-per[i].address, con-per[i].phone);}}else{printf(There is no contact information in the address book!\n);} } 7.清空联系人 又名初始化通讯录。 重新向内存申请一片空间存储联系人信息。 void init_contact(contact* con) {assert(con);// per sz ContactMaxcon-sz 0;person* p (person*)calloc(Max, sizeof(person));if (p NULL){perror(init_contact::calloc);return;}con-per p;con-ContactMax Max; } 8.退出通讯录 通过free()释放内存栈区的空间避免内存泄露。 void destroy_contact(contact* con) {free(con-per);con-per NULL;con-ContactMax 0;con-sz 0;con NULL; } 总结 在使用完内存函数之后一定一定要记得释放空间哦~ 上述代码展示就是整个动态通讯录的全部啦如果你有兴趣想要了解可以通过C_Ccpp/C_study/contact at main · Yjun6/C_Ccpp (github.com)找到它们。
http://www.dnsts.com.cn/news/201405.html

相关文章:

  • 怎么免费注册网站无锡专业做网站的公司有哪些
  • 网站菜单样式网站窗口代码
  • 北京迈程网络网站建设公司公司做网站费用怎么记账
  • 学生个人网站制作软件南京的网站建设
  • 做优惠卷网站倒闭了多少钱网站建设教程搭建
  • 建筑网站大图wordpress 登录很慢
  • 深圳网站建设哪家做网站免费搭建
  • 电子商务网站建设好么律师事务所网站设计方案
  • 湖北海厦建设有限公司网站wordpress修改文章阅读量
  • 衡水网站推广如何用云服务器做网站
  • 推荐营销型网站建设搭建cms网站
  • 网站建设与开发选题淘宝客api采集发布到wordpress
  • 网站空间租用多少钱05网课课练答案
  • 建设网站论文怎样用织梦做网站
  • 手机网站 触屏已有网站 需要整改 怎么做
  • 农安县建设局网站网站建设的安全防护方法
  • 做网站神器物业管理系统功能
  • 网站设计公司青岛在相亲网站做红娘
  • 布吉网站建设技术托管手机桌面布局设计软件
  • 网站设计制作一条龙免费什么网站做软件任务挣钱
  • 购买营销型网站网站空间哪家好
  • 做旅游网站需要的背景微信二维码
  • 旅游网站建设系统江安县建设招标网站
  • 深圳燃气公众号宁波seo网络推广软件系统
  • 绿色食品网站建设可行性三水建设局招标网站
  • 百度右边的网站推荐怎么做的ps制作网站背景
  • 顾村网站建设网站 多国语言
  • 开发一套电商网站多少钱怎么自己做微网站吗
  • 宣传网站建设意义php做网站麻烦吗
  • 如何在自己电脑上搭建网站轻云服务器 wordpress