小练习,新手建议练练手哦
来源:互联网 发布:网络攻击监测网站 编辑:程序博客网 时间:2024/04/30 05:16
在堆上分配一个学生结构体,键盘输入学生的编号、姓名、成绩,提示是否继续输入,选择Y继续输入 选择N 显示输入的所有学员信息,用varglind检查内存,注意内存泄露。
#include<stdio.h>#include<assert.h>#include<stdlib.h>#include<string.h>typedef struct student{ int id; char name[30]; double score;}Stu;int count = 0;void initStruct(Stu* p){ printf("请输入学生的信息:(学号、姓名、成绩):"); char ch = '\0'; int i = 0; scanf("%d %s %lf",&(p[count].id),p[count].name,&(p[count].score)); count++; printf("Y继续,n退出\n");}void outStruct(Stu* p){ int i = 0; for(i = 0;i < count;i++){ printf("%d\t\t%s\t\t%.2lf\n",p[i].id,p[i].name,p[i].score); }}int main(void){ Stu* p = (Stu*)malloc(sizeof(Stu)*10); assert(p); memset(p , 0 ,sizeof(Stu) * 10); char ch = '\0'; int flag = 0; while(1){ initStruct(p); while(getchar() != '\n'); ch = getchar(); if(ch == 'y' || ch == 'Y'){ flag = 1; } if(ch == 'n' || ch == 'N'){ flag = 0; } if(!flag){ outStruct(p); break; }else if (flag == 1){ continue; } } free(p); p = NULL; return 0;}
阅读全文
0 0
- 小练习,新手建议练练手哦
- python多线程小爬虫之练练手
- 练练手
- 两个简单的小程序例子练练手~
- 第一次登录,练练手
- 写博客练练手
- string练练手
- strcpy编程练练手
- 每天练练手
- 每天练练手3.20
- 3.28练练手
- 4.10练练手
- 4_14练练手
- 4.22c++练练手
- js案例练练手
- 练练手[1]
- linux 试题 没事儿 练练手
- 练练手而已,不必当真
- 在linux下搭建apache+mysql+php环境
- Java 注解
- swift 测试
- ConfigReader(二十九)—— ReadHeroHeadConfig
- Redis.conf详解
- 小练习,新手建议练练手哦
- 信息可视化简介
- 每天一道LeetCode-----两个有序数组合并后的第K个数
- 天宝新型GNSS智能目标基站,简化无人机制图
- Android 微信支付和支付宝支付 快速接入
- [转]Windows实用工具Dism++ 10.1.1000.50
- 动态规划算法思想解决找零钱问题
- Eclipse实用操作
- DPDK-实战之rxtx_callbacks(回调函数)