struct init
init struct
2023-09-11 14:22:21 时间
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 }
相关文章
- Linux启动流程和服务管理(init和systemd)
- The ViewStateUserKey property needs to be set during Page_Init.
- ./scripts/init_database.sh: line 2: $‘r‘: command not found
- 能源项目xml文件标签释义--default-lazy-init
- php命令行运行出现错误Call to undefined function curl_init()
- jQuery技术内幕:深入解析jQuery架构设计与实现原理. 2.3 jQuery.fn.init( selector, context, rootjQuery )
- AttributeError: function/symbol 'ARC4_stream_init' not found in library
- Spring源码分析(九)lazy-init 在Spring中是怎么控制加载的
- unix_12c_db_init
- 11g init DB software and database
- wandb.init() bug 踩坑记录
- tomcat启动(五)Catalina分析-service.init
- tomcat启动(四)Catalina分析-server的init()方法
- 华为游戏初始化init失败,返回错误码907135000
- Unity 报错之 Exception: JNI: Init'd AndroidJavaClass with null ptr!
- 疑问:Spring 中构造器、init-method、@PostConstruct、afterPropertiesSet 孰先孰后,自动注入发生时间
- git简单入门之git init /git add /git commit -v
- python__init__的作用