struct init
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <stdbool.h> 5 #define SIZE 5 6 7 typedef struct _student{ 8 char *name; 9 int age; 10 short id; 11 double record; 12 } Student; 13 14 Student *initStudent(){ 15 Student *ptrStu = (Student *)malloc(sizeof(Student)); 16 ptrStu->name = (char *)malloc(sizeof(char) * 20); 17 printf("please input student info: "); 18 printf("\nname: "); 19 scanf("%s", ptrStu->name); 20 printf("age: "); 21 scanf("%d", &ptrStu->age); 22 printf("id: "); 23 scanf("%d", &ptrStu->id); 24 printf("record: "); 25 scanf("%f", &ptrStu->record); 26 27 return ptrStu; 28 } 29 30 void displayStudent(Student *ptrStu){ 31 printf("The student %s's info: \n", ptrStu->name); 32 printf("name: %s\n", ptrStu->name); 33 printf("age: %d\n", ptrStu->age); 34 printf("id: %d\n", ptrStu->id); 35 printf("record: %f\n", ptrStu->record); 36 printf("\n"); 37 38 return; 39 } 40 41 int main(int argc, char **argv) 42 { 43 Student *arrStu[SIZE]; 44 for(int i = 0; i < SIZE; i++){ 45 arrStu[i] = initStudent(); 46 } 47 for(int i = 0; i < SIZE; i++){ 48 displayStudent(arrStu[i]); 49 } 50 51 return 0; 52 }
人就像是被蒙着眼推磨的驴子,生活就像一条鞭子;当鞭子抽到你背上时,你就只能一直往前走,虽然连你也不知道要走到什么时候为止,便一直这么坚持着。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具